Change ports and mount of an existing container

Hi there,
I did not find an answer to this seemingly easy Problem.

I need to change and add ports and mounts to an existing Container in Docker Desktop on ubuntu.

Is there a way to do that?
I tried Docker commit, but while I can start and stop the container via docker start and docker stop I always get an error message no such container when trying to commit the container.

Thank you so much for your help.

No, there is no way and if you need that, that means you are using containers wrong. Not to mention that Docker Desktop is for development so you shouldn’t need to have a longrunning service that you can’t recreate :slight_smile:

docker commit just saves the containers filesystem and some metadata as a new imagelayer and adds an alias to it so you can move the image and start it somewhere else. Using docker commit is usually a bad practice and it will never save anything related to the host machine. So no ports and no mounted folders.


Yes, there is a way to change and add ports and mounts to an existing container in Docker Desktop on Ubuntu. You don’t need to use docker commit for this purpose.

To change ports, you can stop the container using docker stop [container_name], then remove it with docker rm [container_name], and finally run a new container with the updated port mappings using the docker run command.

For adding mounts, you can also stop and remove the container, then run a new container with the additional mounts specified in the docker run command.

The error message “no such container” when trying to commit might be due to incorrect container name or ID. Make sure you are using the correct name or ID in the command.

Remember to back up any important data in the container before making changes.

and yet you are suggesting to remove the container so the answer is still no, there is no way to add these new definitions to an existing container especially not in Docker Desktop.