1

While setting up my first docker environment, I created a specific network:

root@srv /e/docker# docker network inspect docker
[
    {
        "Name": "docker",
        "Id": "7b20560b36032d36ffe6c0ebece6b4408355d207f4e203a2957b0434ee0afdc1",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "10.200.0.0/24"
                }
            ]
        },
        "Internal": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

I created a container from an image for this network with a specific IP:

root@srv /e/docker# docker create --network docker --ip 10.200.0.2 --hostname dev -p 22:22 --name dev base
807f3892241d314d20837c4c749912097e1f34c62884401acd9a06e201cb5876

I then started this container and got:

root@srv /e/docker# docker start dev
Error response from daemon: driver failed programming external connectivity on endpoint dev (807f3892241d314d20837c4c749912097e1f34c62884401acd9a06e201cb5876): Error starting userland proxy: listen tcp 0.0.0.0:22: bind: address already in use
Error: failed to start containers: dev

Indeed, it has supervisord starting sshd -D which by default binds to all available IP addresses for that host. Since its IP is 10.200.0.2, I expected sshd to bind to its 127.0.0.1 and 10.200.0.2. It looks like this port is taken by something but what?

The host does have an sshd running but that should not matter for the guest container, right? (since it lives in its own world which konws only the two IPs above)?

EDIT after comments: In other words, I would like sshd to bind to the IP of the container (the one it sees = 10.200.0.2) and to have this port exposed outside of the container, on the same IP. Or, in practical terms, I would like to be able, from the host, to ssh root@10.200.0.2 and reach the sshd of the container.

  • I'm confused, why are you trying to expose port 22 to the docker guest, it's only running the process you start in the container, which shouldn't be sshd – Jacob Evans Nov 27 '16 at 19:18
  • @JacobEvans: I have sshd running in the container. i would like it to bind to the IP of the container (the one it sees = 10.200.0.2) and to have this port exposed outside of the container, on the same IP. In other words, I would like to be able, from the host, to ssh root@10.200.0.2 and reach the sshd of the container. – WoJ Nov 27 '16 at 19:34
  • @JacobEvans: I updated my question to clarify what I want to achieve. – WoJ Nov 27 '16 at 19:36
  • then you don't need to publish the port, publishing the port does a 1:1 NAT to the host IP, by default from the host you can ssh to any service port on the container – Jacob Evans Nov 27 '16 at 19:37
2

Don't publish the port if you want to connect locally.

/e/docker# docker create --network docker --ip 10.200.0.2 --hostname dev --name dev base

You want to expose the port. https://docs.docker.com/engine/reference/builder/

test/DockerFile

FROM base
EXPOSE 22

docker build -t test -f test/DockerFile test/DockerFile

0

Try amending the -p publish param to bind to a specific IP, for example -p 10.200.0.2:22:22. By default docker publishes the exposed port to 0.0.0.0 if I recall correctly. And as you mentioned, you already have port 22 in-use on the host network.

0

So, the -p flag publishes the port on the host. Just exclude the tag for using it on the container network only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.