Docker - Assign a name to a container using the docker run --name command

by
Jeremy Canfield |
Updated: January 26 2025
| Docker articles
When creating a container using the docker run command the --name option can be used to give the container a specific name.
docker run --name my-container my-image:latest
Of if the container already exists the docker update command can be used.
sudo docker update --name my-container <container ID>
You can use the docker inspect command to view the JSON for the container.
~]$ sudo docker inspect my-container | jq .[].Name
"/my-container"
The docker container ls or docker ps -a command can then be used to display the container. Notice the name of the container is foo.
~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d937372c09ab9 foo:latest "/docker-entrypoin..." 6 minutes ago Created foo
Did you find this article helpful?
If so, consider buying me a coffee over at