Two containers (A,B) were created from the same image.

The two containers have the same mount path (-v) and port number (-p).

The "A" container is currently in the "stop" state. The "B" container is currently running.

Can I change the mount path and port number of the "A" container?

  • 1
    You should note that containers "A" and "B" are totally independent of each other. Whatever you ultimately decide to do to "A", it will have no effects on "B".
    – CAB
    Jan 15 '19 at 15:53

Containers are designed to be disposable. Delete the "A" container and recreate it with the new volume mount and port number. Note that deleting the container will delete any changes made within the container specific RW filesystem layers. If you have changes in there that you need to preserve, then you really want to make those volume mounts. In the end, the workflow looks like:

docker container rm ${old_container_id}
docker container run -v ${new_volume} -p ${new_port} ...

As for changing an existing container, there is:

docker container update ...

however, changing volumes and port bindings are not part of the settings designed to be changed from this. Going under the hood of the docker engine to try to change these settings manually is unsupported and may result in unexpected behavior or a broken engine.


First thing first - two containers cannot run on the same host port, while one container is running or stopped, the port is still attached to it, so that same host port scenario won't come in your case.

Regarding changing the volume mount and to run under another port, you can remove the container A and then start another container with either same name or different name and mount point and ports(free ports) as you want them too.

docker stop A;docker rm A;
docker run --ti \
           --name A \
           -p <desrired host port:desired container port> \
           -v <desired mount point:container mount point> \
           -d your_image:tag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.