brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker rename gives a container a new name without recreating it

Docker
~/tips/tip-docker-rename-container-new-name

docker rename quirky_wozniak web-test

Changes the name of an existing container while it keeps running, with no new container needed.

Docker invents names like quirky_wozniak when you forget --name. Fixing that does not need a new container.

docker ps --format '{{.Names}}'
docker rename quirky_wozniak web-test
docker ps --format '{{.Names}}'

The command takes the current name or ID and the new name. The container keeps its ID, its data and its state. It can be running while you rename it, and the new name shows up immediately in docker ps and in the logs commands.

It is a nice cleanup after a quick experiment that turns out to be worth keeping. A container with a clear name is also easier to find in a month.

The caveat is that a name is more than a label. On user-defined networks, other containers find a container by its name, so after a rename the old name no longer works as an address, and anything that points to it breaks. Compose also keeps track of its containers through labels and names, so renaming a Compose-managed container by hand can lead to confusion, and Compose may create a new one on the next up. For those, change the name in the Compose file instead.

Further reading: docker container rename

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link