Menu
Coddy logo textTech

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 hi

Now 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}}" greeter
challenge icon

Challenge

Beginner

Run 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 hi

Reference the container by name in later commands:

docker inspect --format "{{.Name}}" greeter

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction to Docker