Linux Docker image packaging

Introduction:   This article mainly explains how to install and package Linux Docker images.


For image download, domain name resolution and time synchronization, please click   Alibaba open source mirror station

1, Build Docker environment

1. Installation under linux environment

  • Install / upgrade your Docker client

It is recommended to install Docker client above version 1.10.0. Refer to the document: Docker

  • Configure mirror accelerator

If you want to pull the Docker official image, please install the Docker official image accelerator provided by Alibaba cloud: for users with Docker client version greater than 1.10.0.

1. sudo mkdir -p /etc/docker
2. sudo tee /etc/docker/daemon.json <<-'EOF'
3. {
4. "registry-mirrors": ["http://hd1esep4.mirror.aliyuncs.com"]
5. }
6. EOF
7. sudo systemctl daemon-reload
8. sudo systemctl restart docker

2. Install under Windows & Mac environment

  • To install / upgrade your Docker client:

It is recommended to install Docker client above version 1.10.0. Please visit the installation address on the official website Docker (Windows) or   Docker(Mac).

  • Configure mirror accelerator

If you want to pull the Docker official image, please install the Docker official image accelerator provided by Alibaba cloud: for users with Docker client version greater than 1.10.0.
a) It is recommended to configure the accelerator address when creating a Linux virtual machine.

1. docker-machine create --engine-registry-mirror=<your accelerate address> -d virtualbox default
2. docker-machine env default
3. ****eval**** "$(docker-machine env default)"
4. docker info

b) If you have created a virtual machine through docker machine, you need to modify the configuration by logging in to the machine.

  • First, log in to the virtual machine through docker machine SSH < machine name >.
  • Then, modify the / var/lib/boot2docker/profile file, and add -- registry mirror = < your accelerated address > to EXTRA_ARGS.
  • Finally, execute sudo /etc/init.d/docker restart to restart the Docker service.

2, Making a Doker image

Please refer to the official Docker guidance document, link:

3, Upload Docker image

  • Log in to alicloud Docker Registry

    sudo docker login --username=tb13414881 registry.cn-shanghai.aliyuncs.com

The user name you log in to the Registry is the full name of your alicloud account, and the password is the password you set when you open the service. You can change the login password on the image management homepage.

  • Pull the image from the Registry

    sudo docker pull [Mirror warehouse address]:[Mirror version number]
  • Push image to Registry

    1. sudo docker login --username=tb13414881 
    2. registry.cn-shanghai.aliyuncs.com
    3. sudo docker tag [ImageId] [Mirror warehouse address]:[Mirror version number]
    4. sudo docker push [Mirror warehouse address]:[Mirror version number]

Please replace the ImageId, image warehouse address and image version number parameters in the example according to the actual image information.

  • Select the appropriate mirror warehouse address

When pushing images from ECS, you can choose to use the intranet address of the image warehouse. The push speed will be improved and your public network traffic will not be lost.

If the machine you are using is located on the classic network, please use registry-internal.cn-shanghai.aliyuncs.com as the domain name of the Registry and as the prefix of the image namespace.
If the machine you use is located in the VPC network, please log in with registry-vpc.cn-shanghai.aliyuncs.com as the domain name of the Registry and prefix it with the image namespace.

  • Example

Rename the image using the docker tag command and push it to the Registry through the VPC address.

1. sudo docker images
2. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
3. registry-vpc.cn-shanghai.aliyuncs.com 0.7-dfb6816 37bb9c63c8b2 7 days ago 37.89 MB
4. sudo docker tag 37bb9c63c8b2 registry-vpc.cn-shanghai.aliyuncs.com:0.7-dfb6816

Use the docker images command to find the image and change the domain name in the image name to the Registry VPC address.

sudo docker push registry-vpc.cn-shanghai.aliyuncs.com:0.7-dfb6816

  This article is transferred from: Linux Docker image packaging - alicloud developer community

Keywords: Linux Operation & Maintenance Docker

Added by b2k on Sat, 04 Dec 2021 03:45:12 +0200