Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: Set container name inside Dockerfile

Tags:

Is there a way that I can set what the containers name will be from inside the Dockerfile? Basically I want to always have the same name so I won't have to run "$docker ps" after building and running an image to get its name.

like image 873
Tyler Hilbert Avatar asked May 25 '16 17:05

Tyler Hilbert


People also ask

How do I specify a container name in Dockerfile?

The Dockerfile is for creating images not containers. You can now give names to your containers using the new --name flag for docker run . If --name is not provided Docker will automatically generate an alphanumeric string for the container name.

How do you give your docker image an image name?

If you are consistent if putting the Dockerfile in a directory with the same name as you want for your image, you can use docker build -t $(basename $PWD) . as your build command. Then you can use CTRL-R search from "build" to find and reuse the command and never have to edit it.

How do docker containers get their name?

When a container is created using Docker, Docker provides a way to name the container using the the --name <container_name> flag. However, if no name is provided by the user while creating/running a Docker container, Docker automatically assigns the container a name.


1 Answers

The Dockerfile is for creating images not containers.

You can now give names to your containers using the new --name flag for docker run.

If --name is not provided Docker will automatically generate an alphanumeric string for the container name.

like image 126
Hemerson Varela Avatar answered Sep 23 '22 19:09

Hemerson Varela