编程知识 cdmana.com

Docker learning notes (3) -- container submission & upload image

One 、 Briefly

   The previous article has talked about downloading images 、 function , And the basic operation of the container , The next article is about the submission and upload image of the container .

   For example : If you want your container to be backed up or shared with other users ( The server 、 Other users, etc ), You have to make a copy of the current container and send it to other users ; Or to say , Your current container has deployed an application system running on this machine , Then the test was ok , Want to publish the container to the server to run , It can save time when the server and the local environment are not configured the same , So the process is Docker How is it reflected in ? There is 4 A step :

  1. We can run on this machine after Container submission (commit) Go to the local image warehouse ;

  2. And then local Image upload (push) To DockerHub;

  3. The server / Other user machines , stay DockerHub On Download mirroring (pull);

  4. The server / Other user machines , Run the downloaded image ;

 

One 、 register & Sign in DockerHub user

  Official website address :https://hub.docker.com/

1. register

Click on the above official website address , Register yourself .

 

 

 

2. Sign in

Enter commands in the operating system :docker login

[root@hejl nginx]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: hejianliang
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
You have new mail in /var/spool/mail/root

Follow the steps to enter the user name and password .

 

Two 、 establish DockerHub Mirror address

Log in on the official website DockerHub after , Come to my home page :

 

Click on "Create Repository"

 

Enter the corresponding information , Click on "Create" that will do .

Here's the image repository I've created :

Tags and Scans: The label of the warehouse / edition ;

Docker commands: Indicates the upload of the warehouse (push) command ;

 

3、 ... and 、 Practice - Container submission & Upload the image

List local images ( If there is no mirror image , On their own pull Mirror image ):

[root@hejl nginx]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
hejianliang/centos   java_nginx          7d33387c23ca        17 hours ago        765MB
hejianliang/centos   <none>              f7dbccc37e60        9 days ago          686MB
hejianliang/centos   v1                  4173d0975bbe        2 weeks ago         774MB
centos               latest              0d120b6ccaa8        3 months ago        215MB

List local containers ( If there is no container , On their own run Mirror image ):

[root@hejl nginx]# docker ps -a
CONTAINER ID        IMAGE                           COMMAND             CREATED             STATUS                       PORTS               NAMES
26dc75058b6e        hejianliang/centos:java_nginx   "/sbin/init"        17 hours ago        Exited (137) 4 minutes ago                       centos_java_nginx
a8bde2ae13aa        hejianliang/centos:v1           "/bin/bash"         6 days ago          Exited (0) 6 days ago                            172.18.0.3

Next I'm going to put the container id by "26dc75058b6e" The container of , Submit to image warehouse , Commit syntax :

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
OPTIONS explain :

-a : The author of the image submitted ;

-c : Use Dockerfile Command to create a mirror ;

-m : Instructions for submission ;

-p : stay commit when , Pause container .

Submission of orders :

[root@hejl nginx]# docker commit -a "hejianliang" -m " Integrate Nginx、Tomcat、Keepalived service " -p 26dc75058b6e hejianliang/centos:java_nginx_v2
sha256:9549e4d937c82ab46193b3faabd3bf3f4cb6a46acd54f52199b8d2c0edc66842

Submit successfully ,docker images Mirror the local warehouse :

[root@hejl nginx]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED              SIZE
hejianliang/centos   java_nginx_v2       9549e4d937c8        About a minute ago   801MB
hejianliang/centos   java_nginx          7d33387c23ca        18 hours ago         765MB
hejianliang/centos   <none>              f7dbccc37e60        9 days ago           686MB
hejianliang/centos   v1                  4173d0975bbe        2 weeks ago          774MB
centos               latest              0d120b6ccaa8        3 months ago         215MB

Mirror image "hejianliang/centos:java_nginx_v2" Submitted successfully , The capacity is 801MB, Now let's take the second step to upload the image , Upload Syntax :

docker push [OPTIONS] NAME[:TAG]
OPTIONS explain : --disable-content-trust : Ignore mirror verification , Default on

Upload image command :

[root@hejl nginx]# docker push hejianliang/centos:java_nginx_v2
The push refers to repository [docker.io/hejianliang/centos]
3434a2f802c2: Pushed 
076ecd3c326f: Layer already exists 
291f6e44771a: Layer already exists 
java_nginx_v2: digest: sha256:2f846fabd91e5b78023ead48b7bd3642ba2cdad8446d97f88ce02b0d3908b51d size: 954

Upload image succeeded .

 

Four 、 Practice - Image download

The image has been uploaded to the official website just now , Now we can switch to another machine / This machine ( notes : It needs to be installed on the machine Docker And start the ), Download the uploaded image to the machine .

We can docker Check the image uploaded just now , command :docker search hejianliang

[root@localhost ~]# docker search hejianliang
NAME                 DESCRIPTION         STARS               OFFICIAL            AUTOMATED
hejianliang/centos   centos Warehouse             1                                       
hejianliang/ubuntu                       0 

The warehouse address has been searched out , Next download the image :

[root@localhost ~]# docker pull hejianliang/centos:java_nginx_v2
java_nginx_v2: Pulling from hejianliang/centos
3c72a8ed6814: Pull complete 
0f414fdba906: Pull complete 
a8a9d4720f65: Pull complete 
Digest: sha256:2f846fabd91e5b78023ead48b7bd3642ba2cdad8446d97f88ce02b0d3908b51d
Status: Downloaded newer image for hejianliang/centos:java_nginx_v2
docker.io/hejianliang/centos:java_nginx_v2
[root@localhost ~]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
hejianliang/centos   java_nginx_v2       9549e4d937c8        About an hour ago   801MB
test/ubuntu          v1                  ed488aac8ae1        3 weeks ago         72.9MB
<none>               <none>              9076a9ac1911        3 weeks ago         0B
<none>               <none>              5a5fa4f0a2f9        3 weeks ago         0B
<none>               <none>              03be7b389780        3 weeks ago         0B
<none>               <none>              b74f768c6588        3 weeks ago         72.9MB
rethinkdb            latest              fc02d4327225        4 weeks ago         131MB
hejianliang/ubuntu   15.10               9140108b62dc        6 weeks ago         72.9MB
ubuntu               latest              9140108b62dc        6 weeks ago         72.9MB
hello-world          latest              bf756fb1ae65        10 months ago       13.3kB
ubuntu               15.10               9b9cb95443b5        4 years ago         137MB
training/webapp      latest              6fae60ef3446        5 years ago         349MB

After downloading the image , We do this by looking at the mirror command , our "hejianliang/centos" The image is also in the local warehouse .

The image after downloading , It works as usual , Here we will not operate one by one , You can review the author's previous articles .

 

5、 ... and 、 summary

   Personally think that Docker This container management is very convenient , Is similar to GitHub、MavenRepository etc. , It's easy to use , Just remember more orders ; I didn't use Docker Before , It is to use virtual machine for system deployment test , No problem, then deploy the system to the cloud server . But after experiencing two ways (Docker And virtual machines ), Feeling Docker More efficient , And the operating system environment doesn't have to worry about inconsistencies , There are also more space and memory occupied by virtual machines , It's not as efficient Docker high . That's how I feel about using these two virtual containers .

 

版权声明
本文为[He Jianliang]所创,转载请带上原文链接,感谢

Scroll to Top