This is a problem I had lots of times, and it is possible that I’m not the only one. Scenario:
- I create a container;
- I do some work in the container;
- I need to connect from outside, but I realize that I didn’t map the port.
Or maybe I did, but I need to map it to another port. Or maybe I want to have a volume.
Docker doesn’t natively allow to remap ports or create volumes if a container is already running. When using Docker on localhost for testing, this sucks.
But don’t cry: you don’t need to create a new container.
All you need to do is:
docker stop container bad_container
docker commit bad_container good_image
docker run --name good_container -d -p ... -v ... good_image