Docker – how to rerun a container with different flags

In case you want to rerun a running container with different flags (e.g. -p port1:port2), you can follow these steps.

  1. 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
  2. Delete old container (in case we want to reuse its name)

    $ docker rm nginxphp1
  3. Use docker run to create new container from nginxphp1_live

    $ docker run -it -p 8081:80 --name nginxphp1 nginxphp1_live /bin/bash
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments