Answers: <p>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:</p>
  
  <pre><code>docker container rm ${old_container_id}
  docker container run -v ${new_volume} -p ${new_port} ...
  </code></pre>
  
  <p>As for changing an existing container, there is:</p>
  
  <pre><code>docker container update ...
  </code></pre>
  
  <p>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.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-01-14T14:50:04.837Z
Answers: 2019-01-14T14:50:04.837Z
Answers: BMitch
Answers: <p>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. </p>
  
  <p>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.</p>
  
  <pre><code>docker stop A;docker rm A;
  docker run --ti \
             --name A \
             -p &lt;desrired host port:desired container port&gt; \
             -v &lt;desired mount point:container mount point&gt; \
             -d your_image:tag
  
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-01-16T12:33:39.860Z
Answers: 2019-01-16T12:50:18.740Z
Answers: 2019-01-16T12:50:18.740Z
Answers: rebelution
Body: <p>Two containers (A,B) were created from the same image.</p>
  
  <p>The two containers have the same mount path (-v) and port number (-p).</p>
  
  <p>The "A" container is currently in the "stop" state.
  The "B" container is currently running.</p>
  
  <p>Can I change the mount path and port number of the "A" container?</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-01-15T15:53:50.353Z
Comments: 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".
Comments: CAB
Tags: <docker>
Title: Can I change the mount path and port number of a built container?
UserDisplayName: ASH
ThreadText: # Can I change the mount path and port number of a built container?
  
  (Asked by: username_0 on 2019-01-14)
  
  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?
  
  **Tags:** docker
  
  > **Comments:**
  > **username_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".  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2019-01-14. Score: 1
  
  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.
  
  
  ---
  
  ### Answer by username_3 on 2019-01-16. Score: 0
  
  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
  
  ```
  
  
  ---
  
  