When I build an image using docker build
:
docker build .
I get an image with a random name.
How to create a docker image with a custom name?
I already know how to set the name in the Dockerfile
, but I'm not sure how to use it in the build
command.
To build a docker image from a file named other than Dockerfile, specify the Dockerfile name using the -f option. The above command will build the docker image by reading instructions from Dockerfile. dev file in /home/$USER directory.
You can rename your docker image by docker tag command. Use the below given command to do that. To rename docker container, use the rename sub-command as shown, in the following example, we renaming the container discourse_app to a new name disc_app.
You can use the -t
flag, as shown in the documentation (or run docker build --help
to learn about the options you have).
You should do:
docker build -t my-image .
Now the image is created with the name my-image
:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my-image latest 43070bef9dfa 2 minutes ago 464MB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With