Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why port not found? #183

Closed
softshipper opened this issue Apr 20, 2020 · 2 comments
Closed

Why port not found? #183

softshipper opened this issue Apr 20, 2020 · 2 comments
Labels
question Have you tried our Slack (https://testcontainers.slack.com)?

Comments

@softshipper
Copy link

softshipper commented Apr 20, 2020

Hi all

I am trying to use https://github.com/testcontainers/testcontainers-go as follows:

func TestGitAutoTag(t *testing.T) {

	path, err := os.Getwd()
	assert.NoError(t, err, err)

	fmt.Println(path)
	data := fmt.Sprintf("%s%s", path, "/gogs/data")

	fmt.Println(data)

	//Start gogs container
	ctx := context.Background()
	req := testcontainer.ContainerRequest{
		Image:        "gogs/gogs:0.11.91",
		ExposedPorts: []string{"3000/tcp"},
		WaitingFor:   wait.ForHTTP("/"),
		BindMounts:   map[string]string{data: "/data"},
		Name:         "gogs",
	}

	gogs, err := testcontainer.GenericContainer(ctx, testcontainer.GenericContainerRequest{
		ContainerRequest: req,
		Started:          true,
	})

	assert.NoError(t, err, err)


	defer gogs.Terminate(ctx)

}

and it shows:

TestGitAutoTag: auto_tagger_test.go:38: 
    	Error Trace:	auto_tagger_test.go:38
    	Error:      	Received unexpected error:
    	            	port not found
    	            	github.com/testcontainers/testcontainers-go.(*DockerContainer).MappedPort  

It should be alias to:

docker run --rm -it -p 3000:3000 --name=gogs --mount type=bind,source=`pwd`/gogs/data,target=/data gogs/gogs

What am I doing wrong?

Thanks

@gianarb gianarb added the question Have you tried our Slack (https://testcontainers.slack.com)? label Apr 20, 2020
@gianarb
Copy link
Collaborator

gianarb commented Apr 20, 2020

Hello @softshipper

By default the wait.HTTP uses port 80. You have to override the port

		WaitingFor:   wait.ForHTTP("/").WithPort("3000/tcp"),

@gianarb gianarb added type/bug and removed type/bug labels Apr 20, 2020
@gianarb gianarb closed this as completed Apr 20, 2020
gianarb pushed a commit that referenced this issue Apr 20, 2020
Based on the issue #183 I decided to add this example to explain that by
default wait.HTTP looks for port `80/tcp` but you can override it.

Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
This was referenced Apr 20, 2020
@softshipper
Copy link
Author

softshipper commented Apr 20, 2020

It takes a long time(61.56s):

2020/04/20 14:41:45 Starting container id: 7579b1bb43b0 image: quay.io/testcontainers/ryuk:0.2.3
2020/04/20 14:41:46 Waiting for container id 7579b1bb43b0 image: quay.io/testcontainers/ryuk:0.2.3
2020/04/20 14:41:46 Container is ready id: 7579b1bb43b0 image: quay.io/testcontainers/ryuk:0.2.3
2020/04/20 14:41:46 Starting container id: fd311e02b8cd image: gogs/gogs:0.11.91
2020/04/20 14:41:46 Waiting for container id fd311e02b8cd image: gogs/gogs:0.11.91
2020/04/20 14:42:46 Container is ready id: fd311e02b8cd image: gogs/gogs:0.11.91
--- PASS: TestGitAutoTag (61.56s)
=== RUN   TestGitAutoTag/Last_commit_does_not_have_a_tag
    --- PASS: TestGitAutoTag/Last_commit_does_not_have_a_tag (0.00s)
=== RUN   TestGitAutoTag/Last_commit_already_be_tagged
    --- PASS: TestGitAutoTag/Last_commit_already_be_tagged (0.00s)
=== RUN   TestGitAutoTag/Repository_requires_password
    --- PASS: TestGitAutoTag/Repository_requires_password (0.00s)
=== RUN   TestGitAutoTag/Commit_message_does_not_contain_[MAJOR],_[MINOR],_[PATCH]
    --- PASS: TestGitAutoTag/Commit_message_does_not_contain_[MAJOR],_[MINOR],_[PATCH] (0.00s)
PASS

Why?

One more question, how to specify bind like:
--mount type=bind,source=pwd/gogs/data,target=/data
I've tried

	req := testcontainer.ContainerRequest{
		Image:        "gogs/gogs:0.11.91",
		ExposedPorts: []string{"3000/tcp"},
		WaitingFor:   wait.ForHTTP("/").WithPort("3000/tcp"),
		BindMounts:   map[string]string{data: "/data"},
		Name:         "gogs",
	}

But it does not work. I would like to create a test like:
docker run --rm -it -p 3000:3000 --name=gogs --mount type=bind,source=pwd/gogs/data,target=/data gogs/gogs

Could you please try it.

Here is the project folder:

auto-git-tagger.zip

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Have you tried our Slack (https://testcontainers.slack.com)?
Projects
None yet
Development

No branches or pull requests

2 participants