Renaming a container takes one command, and the trouble arrives afterwards, when a script, monitor or teammate still asks for the old name. This guide uses docker rename to change a container's name, confirm the new name works, and keep a simple way back. It takes about five minutes when you already know the container name.
The rename changes the container's name, not its image, filesystem contents or published ports.
5:29.8.1-1~ubuntu.24.04~noble. The local manual page is dated September 2026 and documents docker rename CONTAINER NEW_NAME as an alias for docker container rename.sudo.Security warning: do not add sudo automatically. Membership of the Docker group is already a privileged arrangement, and running the CLI as root can make file ownership and configuration checks harder to reason about.
Checkpoint: confirm the client and its command syntax before touching a container:
$ docker --version
Docker version 29.8.1, build 4a63305
$ docker rename --help
Usage: docker rename CONTAINER NEW_NAME
The build identifier can differ on another installation. What matters is that Docker responds and the usage line takes one existing container followed by one new name.
List all containers, including stopped ones, and record the current name. A rename does not start a stopped container, so including them stops you acting on the wrong object or assuming a missing running container has vanished.
$ docker ps -a --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}'
CONTAINER ID NAMES STATUS IMAGE
7f3a1c2d4e5f web-old Up 2 hours nginx:latest
91ab2cd3ef45 worker-old Exited (0) alpine:latest
The IDs and status text are examples. Replace web-old with an exact name from your own output. Names are easier to review than a short ID, but the command accepts a container ID too.
Do not rename from a partial or visually similar value. If the list is unexpectedly empty, check the Docker context with docker context show and confirm you are connected to the daemon that owns the container. Changing context can expose a different set of containers without changing any container.
Choose a new name that is clear to people and stable for scripts. Check that it is not already taken:
$ docker ps -a --format '{{.Names}}' | grep -Fx -- 'web-new'
$ printf 'grep exit status: %s\n' "$?"
grep exit status: 1
No output and status 1 mean the exact name was not listed. If you see the name, stop and choose another. The destination must be a valid, unused Docker container name. Keep shell metacharacters and whitespace out of names: quoting protects the shell, but it does not make an unsuitable Docker name suitable.
Checkpoint: write down the mapping before you change anything:
old name: web-old
new name: web-new
Renaming a running container can affect monitoring, scripts and operators that address it by name. It does not recreate or restart the container, but name-based references can fail the moment the change lands. If the service is busy, announce the change or follow its maintenance procedure first.
Warning: there is no destructive delete in this command, but the change is still disruptive for name-dependent automation. Keep the old and new names visible while you update those references.
$ docker rename web-old web-new
A successful Docker CLI command normally returns to the prompt without a success message. A non-zero exit status means the daemon rejected the request. If the command was interrupted, do not assume the rename happened. Verify in the next step.
Ask Docker for the container by its new name, and check the old name is no longer listed:
$ docker ps -a --filter 'name=^web-new$' --format '{{.ID}} {{.Names}} {{.Status}}'
7f3a1c2d4e5f web-new Up 2 hours
$ docker ps -a --filter 'name=^web-old$' --format '{{.Names}}'
$ docker inspect --format '{{.Name}}' web-new
/web-new
The ID should match the one from before the rename (yours will differ from the example), and the status should show the same running or stopped state. docker inspect prints a leading slash on the container name. That is normal Docker output, not part of the name you type.
Checkpoint: a successful rename proves the Docker object has a new name. It does not prove every external configuration has caught up, so check the application separately if the name is used by a network alias, backup job or service definition.
First update the script, compose file, systemd unit or monitoring rule that should use web-new. Search configuration before editing it:
$ rg -n --fixed-strings 'web-old' /path/to/project
Use the real project path, and review each match rather than replacing text across an unrelated directory. If you need the original name back while you coordinate the update, run:
$ docker rename web-new web-old
$ docker inspect --format '{{.Name}}' web-old
/web-old
Recovery: that undo changes the name back. It does not restore edits already made to scripts or monitoring. If the old name is already occupied, resolve that separate conflict before attempting the rollback.
docker ps -a and the active context. The container may belong to another daemon.