Search code examples
dockerportrancher

Docker: How to start an existing container and forward the ports?


I am new to docker and I'm trying to get a permanent installation of Rancher started. To create the docker container I run the following command:

docker run -d --name rancher-server -p 8080:8080 rancher/server

Note that I want to forward the container's 8080 port to my hosts' 8080, since 80 is occupied by nginx on my host.

Now, when I stop the above container and try to start it again using docker start <Container ID> I get the following error:

Error response from daemon: driver failed programming external connectivity on endpoint rancher-server (c18940f957ed1f737fd5453ea29755adea762d758643a64984d5e3ce8bd3fdbe): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use Error: failed to start containers: c93794a8c0ad

I know that this happens since nginx is using port 80, so my question is how do I start my existing container and tell it to forward its ports?

Running docker start -d -p 8080:8080 c93794a8c0ad gives me the following error: unknown shorthand flag: 'd' in -d

So how do I start a container with forwarded ports? Thank you!


Solution

  • I deleted the container and created a new one with the command the Rancher docs recommend sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server and now stopping and starting the container work as expected, on the correct ports. I don't know what the problem was before, but it now works.