Naming Containers
Part of the Introduction to Docker section of Coddy's Terminal journey — lesson 12 of 40.
By default Docker gives every container a random name like charming_tu. That is hard to refer to later, so you can choose your own name with the --name flag:
docker run --name greeter alpine echo hiNow the container is called greeter, and you can use that name in any later command instead of a random ID.
You can confirm the name was used by inspecting the container's configured image, addressing it by the name you gave it:
docker inspect --format "{{.Name}}" greeterChallenge
BeginnerRun an alpine container named worker that prints ready with echo. Use the --name flag.
Cheat sheet
Use --name to assign a custom name to a container:
docker run --name greeter alpine echo hiReference the container by name in later commands:
docker inspect --format "{{.Name}}" greeterTry it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Introduction to Docker
4Managing Containers
Naming ContainersDetached ContainersListing All ContainersStopping And RemovingRecap - Container Lifecycle