web123456

Docker (II): images, container import and export and private repository setup

🟢 Docker (B): Images, containers import and export and private repository construction

  • I. Docker image, container import and export
    • 1.1 Exporting Docker images
    • 1.2 Loading Docker images
    • 1.3 Exporting Docker Containers
    • 1.4. Importing Docker containers
  • The difference between exporting and importing mirrors and containers.
  • Third, commit operation_local image released to the AliCloud
    • 3.1 Steps related to the commit operation
    • 3.2. Use the "docker push" command to submit the centos image to AliCloud.
  • Fourth, Docker private repository building (registry)
    • 4.1. Downloading mirrors
    • 4.2. Viewing
    • 4.3 Running the registry
    • 4.4.Test uploading image to Registry


💖The Begin💖 Tap to follow and collect without getting lost 💖

在这里插入图片描述

I. Docker image, container import and export

1.1 Exporting Docker images

docker save [options]  images [images...]

docker save > uu.tar ubuntu:latest
or
docker save ubuntu:latest > uu.tar
  • 1
  • 2
  • 3
  • 4
  • 5

1.2 Loading Docker images

# Operate in the folder where the image package is located
docker load --input  uu.tar
# can also be used
docker load -i uu.tar
or
docker load< uu.tar
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

1.3 Exporting Docker Containers

docker export containerid/name (of a thing)> Exported paths

docker export 220aee82cfea> -o mysql.tar.gz
  • 1
  • 2
  • 3

1.4. Importing Docker containers

Importing containers
dockerimport  - mirror user/Mirror name: mirror version number

cat mysql.tar.gz | docker import - test/mysql:5.7
  • 1
  • 2
  • 3
  • 4

The difference between exporting and importing mirrors and containers.

1. Mirror Import YesreplicatedProcess.
2. Container import is to turn the current container into a new image.

Difference between save and export:

1) save Saves all information about the image - including historical information.
(2) export exports only the current information.

First, they operate on different objects. docker save saves an image as a tarball, while docker export saves a container snapshot as a tarball.

Then, the container snapshot file exported by docker export will discard all the history and metadata information, i.e., it only saves the snapshot state of the container at that time; whereas, the image storage file saved by docker save will save the complete record and is larger in size.

Third, commit operation_local image released to the AliCloud

3.1 Steps related to the commit operation

Commit the container copy to become a new image.

docker commit -m="Information submitted" -a="Author." Container ID The name of the target image to be created:[label name]
  • 1

Local mirrors are published to AliCloud:

  1. Login to AliCloud Docker Registry

在这里插入图片描述

$ docker login --username=aliyun075054**** registry.cn-hangzhou.aliyuncs.com
The username used to log in is the full name of your Aliyun account, and the password is the one you set when you activate the service.
You can change your credentials password on the Access Credentials page.
  • 1
  • 2
  • 3
  1. Pulling images from the Registry
$ docker pull registry.cn-hangzhou.aliyuncs.com/zhaohaibao/centos:[Image version number]
  • 1
  1. Push the image to the Registry
$ docker login --username=aliyun075054**** registry.cn-hangzhou.aliyuncs.com
$ docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/zhaohaibao/centos:[Image version number]
$ docker push registry.cn-hangzhou.aliyuncs.com/zhaohaibao/centos:[Image version number]
Please replace the example with the actual mirror information.[ImageId]cap (a poem)[Image version number]Parameters.
  • 1
  • 2
  • 3
  • 4
  1. Choose the right mirror repository address
When pushing mirrors from ECS, you can choose to use the mirror repository intranet address. Push speeds will be increased and you will not lose public traffic.
If you are using a machine on a VPC network, use the registry-vpc.cn-hangzhou.aliyuncs.com as the Registry's domain name login.
  • 1
  • 2
  1. typical example
utilization"docker tag"command renames the image and pushes it to the Registry via a proprietary network address.
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry.aliyuncs.com/acs/agent 0.7-dfb6816 37bb9c63c8b2 7 days ago 37.89 MB
$ docker tag 37bb9c63c8b2 registry-vpc.cn-hangzhou.aliyuncs.com/acs/agent:0.7-dfb6816
Use"docker push" command to push that image to the remote.
$ docker push registry-vpc.cn-hangzhou.aliyuncs.com/acs/agent:0.7-dfb6816
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

3.2. Use the "docker push" command to move thecentosMirror Submission to AliCloud

#### submits the centos image IMAGE ID (5d0da3dc9764) to Aliyun
[root@zyl-server ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
nginx         latest    605c77e624dd   19 months ago   141MB
hello-world   latest    feb5d9fea6a5   23 months ago   13.3kB
centos        latest    5d0da3dc9764   23 months ago   231MB
[root@zyl-server ~]# docker tag 5d0da3dc9764  /zhaohaibao/centos:7.9
[root@zyl-server ~]# docker push  /zhaohaibao/centos:7.9
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/zhaohaibao/centos]
74ddd0ec08fa: Layer already exists 
7.9: digest: sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3aab063a7fdb9dc size: 529
[root@zyl-server ~]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

在这里插入图片描述

在这里插入图片描述

Fourth, Docker private repository building (registry)

4.1. Downloading mirrors

[root@zyl-server ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
79e9f2f55bf5: Pull complete 
0d96da54f60b: Pull complete 
5b27040df4a2: Pull complete 
e2ead8259a04: Pull complete 
3790aef225b9: Pull complete 
Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@zyl-server ~]# 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

4.2. Viewing

[root@zyl-server ~]# docker images
  • 1

在这里插入图片描述

4.3 Running the registry

docker run -d  -p 5000:5000 -v /zyl/myregistry/:/tmp/registry  --privileged=true registry
By default, the repository is created in the container's/var/lib/In the registry directory, it is recommended to map the container data volume by itself to facilitate the host interconnection

[root@zyl-server ~]# docker run -d  -p 5000:5000 -v /zyl/myregistry/:/tmp/registry  --privileged=true registry
4c3babd80e86c8e2b21f4ad1dffeec5ca42270e5d467bed2a93839e323bcd5c6
[root@zyl-server ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED             STATUS             PORTS                                       NAMES
4c3babd80e86   registry   "/ /etc…"   10 seconds ago      Up 8 seconds       0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   amazing_rhodes
780530eaf656   centos     "/bin/bash"              About an hour ago   Up About an hour                                               wizardly_dhawan
95420eae9ad9   nginx      "/docker-entrypoint.…"   About an hour ago   Up About an hour   80/tcp                                      great_pasteur
[root@zyl-server ~]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

在这里插入图片描述
A browser visit to http://IP:5000/v2 shows "{}" indicating that registry is working fine.

在这里插入图片描述

4.4.Test uploading image to Registry

1. Submit the centos container copy to become a new image, Tag----" 1.2 .

[root@zyl-server ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED             STATUS             PORTS                                       NAMES
4c3babd80e86   registry   "/ /etc…"   5 minutes ago       Up 5 minutes       0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   amazing_rhodes
780530eaf656   centos     "/bin/bash"              About an hour ago   Up About an hour                                               wizardly_dhawan
95420eae9ad9   nginx      "/docker-entrypoint.…"   2 hours ago         Up 2 hours         80/tcp                                      great_pasteur
[root@zyl-server ~]# docker commit -m="centos" -a="zyl" 780530eaf656 centos:1.2
sha256:d0a52e21dd65f98f7cd106d996e97e1b3e709431e4bb80cd2e3599953fa95fe6
[root@zyl-server ~]# docker images
REPOSITORY                                            TAG       IMAGE ID       CREATED          SIZE
centos                                                1.2       d0a52e21dd65   20 seconds ago   231MB
nginx                                                 latest    605c77e624dd   19 months ago    141MB
registry                                              latest    b8604a3fe854   21 months ago    26.2MB
hello-world                                           latest    feb5d9fea6a5   23 months ago    13.3kB
centos                                                latest    5d0da3dc9764   23 months ago    231MB
registry.cn-hangzhou.aliyuncs.com/zhaohaibao/centos   7.9       5d0da3dc9764   23 months ago    231MB
[root@zyl-server ~]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

在这里插入图片描述

2. View the current private repository mirror (empty)

[root@zyl-server ~]# curl -XGET http://192.168.234.10:5000/v2/_catalog
{"repositories":[]}
[root@zyl-server ~]# 
  • 1
  • 2
  • 3

3. Name the host's registry image in a format that meets the repository requirements.registry_url:port/ImageName:tag

docker tag centos:1.2 192.168.234.10:5000/centos:1.2
  • 1

在这里插入图片描述

4, upload centos image to the Registry repository

docker push 192.168.234.10:5000/centos:1.2
  • 1

push failed:

[root@zyl-server ~]# docker push 192.168.234.10:5000/centos:1.2
The push refers to repository [192.168.234.10:5000/centos]
Get "https://192.168.234.10:5000/v2/": http: server gave HTTP response to HTTPS client
[root@zyl-server ~]# 

  • 1
  • 2
  • 3
  • 4
  • 5

Solution:

This is because the registry service we started is not secure and trustworthy. At this point you need to modify the client docker configuration file vi/etc/docker/daemon.json.



Add the following (insecure)-(registries service address):

{
""registry-mirrors": ["https://XXX.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.234.10:5000"]
}
   "registry-mirrors": [""] is the address of the Registry Hub repository represented by Aliyun, which can speed up domestic access to the Registry Hub repository.

You need to restart the Docker service for the changes to take effect.

Execute the command: systemctl restart docker , and then push can be.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

在这里插入图片描述
5. Push again

[root@zyl-server ~]# docker push 192.168.234.10:5000/centos:1.2
The push refers to repository [192.168.234.10:5000/centos]
Get "http://192.168.234.10:5000/v2/": dial tcp 192.168.234.10:5000: connect: connection refused
[root@zyl-server ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@zyl-server ~]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Error.connect: connection refused

Solution: docker ps view finds no running image instances and re-runs the registry.

docker run -d  -p 5000:5000 -v /zyl/myregistry/:/tmp/registry  --privileged=true registry

### push

docker push 192.168.234.10:5000/centos:1.2
  • 1
  • 2
  • 3
  • 4
  • 5

在这里插入图片描述

6, check - view the current private repository mirror

[root@zyl-server ~]# curl -XGET http://192.168.234.10:5000/v2/_catalog
{"repositories":["centos"]}
[root@zyl-server ~]# 

  • 1
  • 2
  • 3
  • 4

在这里插入图片描述
在这里插入图片描述


At this point, our Registry private repository is complete, if you want to use it in the future, you can use the command:

docker pull 192.168.234.10:5000/centos:1.2
  • 1

💖The End💖 Tap to follow and collect without getting lost 💖