This article describes how to create a simple container image with Docker
and share it with Docker Hub
.
Since this is a beginner's article, I would appreciate it if you could point out any mistakes.
You have Docker
installed.
If you have not installed it, please install it by referring to the link below.
Maybe it works! Let's get started with Docker!
In order to create a container image, you need to create a Dockerfile
that is the contents of the container.
Write the following code and save it as Dockerfile
.
Docekrfile
FROM ubuntu:20.04
CMD ["echo", "hello Docker!!"]
The content of the code calls the operating system ʻubuntuand outputs
hello Docker !!`.
In your terminal, go to the Dockerfile
directory and hit the docker build
command.
$ docker build -t hellodoc .
The -t
option allows you to specify an image name.
.
Indicates the path where the Dockerfile
is located. It's .
because I'm typing the command in the directory where the Dockerfile is located.
After the build process is finished, try moving the container image.
$ docker run hellodoc
hello Docker!!
It worked fine!
You can see the list of local container images with the docker images
command.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hellodoc latest 32d0a84555ac 2 weeks ago 72.9MB
If you can confirm the operation of the container image, it will just display ~~ hello Docker !! ~~ Let's share the container image with Docker Hub
.
As you can see from the name, Docker Hub
is like Docker
of Git Hub
(personal recognition), and various container images are published.
If you don't have a Docker Hub
account, go to the Docker Hub sign-up page (https://hub.docker.com/signup/) and sign up.
Log in to Docker Hub
from your terminal.
$ docker login -u ■■■■■■■■■
Password: ************
Login Succeeded
Enter the registered user account in ■ and the password in *.
Build in a format for sharing container images.
docker build -t ■■■■■■■■■/hellodoc:1.0.0 .
There is a rule in the image name naming convention for sharing.
Docker Hub
account name before the image name. (Please change the part of ■ to your own Docker Hub
account name.):
and the version after the image name.Register the container image with the docker push
command.
$ docker push ■■■■■■■■■/hellodoc:1.0.0
Let's check with Docker Hub
when the process is finished.
You are registered properly!
The registered container image can be downloaded locally with the docker pull
command.
docker pull ■■■■■■■■■/hellodoc:1.0.0
Recommended Posts