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

Network host option works not with expected behavior #138

Closed
Bablzz opened this issue Jan 27, 2020 · 4 comments
Closed

Network host option works not with expected behavior #138

Bablzz opened this issue Jan 27, 2020 · 4 comments

Comments

@Bablzz
Copy link
Contributor

Bablzz commented Jan 27, 2020

Hello everyone!

Thanks for excellent library!

I've got stack an one problem. Maybe you can help me. Maybe I don't understand something

Thanks in advance!

PS. Library v.0.0.10

Describe the bug
Network host option works not with expected behavior

To Reproduce

func TestContainerWithHostNetworkOptions(t *testing.T) {
	ctx := context.Background()
	gcr := testcontainers.GenericContainerRequest{ContainerRequest: testcontainers.ContainerRequest{
		Image:    "nginx",
		Networks: []string{"host"},
	},
		Started: true,
	}

	nginxC, err := testcontainers.GenericContainer(ctx, gcr)
	if err != nil {
		fmt.Errorf("Error %s", err)
	}

	host, err := nginxC.Host(ctx)

	resp, err := http.Get("http://" + host + ":80")
	if err != nil {
		t.Error(err)
	}
	t.Log(resp)
}

=> golang.org/x/sys/unix.ECONNREFUSED (111)

Expected behavior
When I use Networks: []string{"host"} I expect the same behavior as docker run --net host

** docker info **
output of the command:

docker info
Client:
 Debug Mode: false

Server:
 Containers: 11
  Running: 2
  Paused: 0
  Stopped: 9
 Images: 12
 Server Version: 19.03.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.0.0-37-generic
 Operating System: Ubuntu 19.04
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.43GiB
 Name: 
 ID: 
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional context
I've tried to add option like ExposedPorts but I've got the same error.
But if I delete Networks "host" options and add ExposedPorts it works

@gianarb
Copy link
Member

gianarb commented Jan 30, 2020

Thank you for providing the test!
I will try to figure out what is going on next week

@Bablzz
Copy link
Contributor Author

Bablzz commented Jan 31, 2020

@gianarb I've debugged a little bit and I've founded out something.
Example

docker run --net host ...
docker inspect ...

I see

        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "host"

"NetworkMode": "host"

When I use this library I see

        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default"

"NetworkMode": "default"

I can make PR if you don't mind.

@gianarb
Copy link
Member

gianarb commented Jan 31, 2020 via email

gianarb added a commit that referenced this issue Feb 3, 2020
@Bablzz Bablzz closed this as completed Feb 3, 2020
@Bablzz
Copy link
Contributor Author

Bablzz commented Feb 3, 2020

Fixed

fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants