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

Port mapping and concurrent containers #51

Closed
FreeSpace911 opened this issue Nov 19, 2017 · 4 comments
Closed

Port mapping and concurrent containers #51

FreeSpace911 opened this issue Nov 19, 2017 · 4 comments
Labels

Comments

@FreeSpace911
Copy link

Hello,
I have created one container with the following command:

[username@localhost ~]# docker run -d -p 5901:5901 -e VNC_RESOLUTION=1920x1080 -p 6901:6901 consol/ubuntu-xfce-vnc c6e7194d9ed19f2f291d6cd1925a4352965c37c6692adf2c502e6cf47226a91c

And then when I tired to create another container on the same host with different port number I got the following error:
[username@localhost ~]# docker run -d -p 5901:5901 -e VNC_RESOLUTION=1920x1080 -p 6902:6902 consol/ubuntu-xfce-vnc bb77aa923ed98642601049703bfdc8712cc34b2467aa5f235a61c24c41ea3341 /usr/bin/docker-current: Error response from daemon: driver failed programming external connectivity on endpoint pedantic_pasteur (1593ca8771edb808e917ee5e60a2a2d07c0e63a8fb8ed38a4d42e50cbf6145a6): Bind for 0.0.0.0:5901 failed: port is already allocated.

So, what is the right way in order to mange this scenario?
Thanks!

@plaihonen
Copy link

You have "-p 5901:5901" in both containers.

@FreeSpace911
Copy link
Author

Hello @plaihonen ,
Changing the 5901 port number will create the container but without connectivity! This is the local VNC port number.

@plaihonen
Copy link

@FreeSpace911,
You only change the port for the host 0.0.0.0, not for the container.
Per your error message, Bind for 0.0.0.0:5901 failed: port is already allocated., you can not bind the 5901 twice.

See the docker run documentation ( the -p [ ] format )
https://docs.docker.com/engine/reference/run/#expose-incoming-ports

@toschneck
Copy link
Contributor

Like already mentioned you have correct your docker port mapping. That's the normal behavior like other docker images would also do. You also can use the -P what choose random port:

docker run --help
...
     -p, --publish list                   Publish a container's port(s) to the host
     -P, --publish-all                    Publish all exposed ports to random ports`

If you wan to have multiple instances with an specific port, just increase your first port number, e.g.:

docker run -d -p 5901:5901 -e VNC_RESOLUTION=1920x1080 -p 6901:6901 -d consol/ubuntu-xfce-vnc
docker run -d -p 5902:5901 -e VNC_RESOLUTION=1920x1080 -p 6902:6901 -d consol/ubuntu-xfce-vnc

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

No branches or pull requests

3 participants