Using names in Docker
So far, when we've operated on containers, we've always used autogenerated names. This approach has some advantages, such as the names being unique (no naming conflicts) and automatic (no need to do anything). In many cases, however, it's better to give a user-friendly name to a container or an image.
Naming containers
There are two good reasons to name a container: convenience and the possibility of automation. Let's look at why, as follows:
- Convenience: It's simpler to make any operations on a container when addressing it by name than by checking the hashes or the autogenerated name.
- Automation: Sometimes, we would like to depend on the specific naming of a container.
For example, we would like to have containers that depend on each other and to have one linked to another. Therefore, we need to know their names.
To name a container, we use the --name
parameter, as follows...