By default, containers created with docker run
are given a random name like small_roentgen
or modest_dubinsky
. These names aren't particularly helpful in identifying the purpose of a container. It is possible to supply a name for the container by passing the --name
command line option:
docker run --name my-ubuntu ubuntu:14.04
Names must be unique; if you pass a name that another container is already using, Docker will print an error and no new container will be created.
Specifying a name will be useful when referencing the container within a Docker network. This works for both background and foreground Docker containers.
Containers on the default bridge network must be linked to communicate by name.