In case you want to rerun a running container with different flags (e.g. -p port1:port2
), you can follow these steps.
-
Stop the container and commit to a live image. Assuming container name is nginxphp1 and image name is nginxphp1_live, we an use the following commands:
$ docker stop nginxphp1 nginxphp1_live $ docker commit nginxphp1 nginxphp1_live
-
Delete old container (in case we want to reuse its name)
$ docker rm nginxphp1
-
Use docker run to create new container from nginxphp1_live
$ docker run -it -p 8081:80 --name nginxphp1 nginxphp1_live /bin/bash