Difficulty: Beginner
How do you rename an existing Docker container, and what changes or stays the same when you do?
Use docker rename <current_name_or_id> <new_name>. It works on both running and stopped containers, takes effect instantly without restarting anything, and changes only the human-friendly name; the container ID, configuration, filesystem and running processes stay exactly the same.
Every container has a 64-character ID and a name. If you do not pass --name, Docker generates a random one like eager_hopper. Names are what you type in day-to-day commands (docker logs api), what scripts target, and, on user-defined networks, what other containers use as a DNS hostname to reach this one. Renaming is useful when you started a container without --name, when you want to keep an old version around (api becomes api-old before starting a new api), or to fix a naming convention.
_, . and -.--network-alias are separate and not changed.docker rename; use docker tag to give an image a new name.A small but handy pattern on a single server:
docker rename api api-olddocker run -d --name api --network app my-api:2.0docker logs api and the health endpoint.docker rm -f api-old; if not, stop the new one and rename api-old back.<project>-<service>-<n> convention and confuses humans. Change the Compose file instead.# Started without --name, so Docker picked one
docker run -d nginx:1.27-alpine
docker ps --format '{{.ID}} {{.Names}}'
# Give it a meaningful name (running container, no restart)
docker rename eager_hopper web-proxy
docker ps --format '{{.ID}} {{.Names}}'
# Name already in use
docker rename web-proxy db
The ID stays a1b2c3d4e5f6 across the rename; only the name changes, and a duplicate name is rejected.
docker rename, Container Names, Container ID, Name Conflicts