1. Install

1. Configure the yum source

```
sudo yum-config-manager \

>     --add-repo \
>     https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo  
```
Copy the code

2. Configure the YUM repository

sudo sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
Copy the code

3. Yum

sudo yum-config-manager --enable docker-ce-test
Copy the code

4. Install the docker

yum install docker-ce docker-ce-cli containerd.io --allowerasing
Copy the code

2. Configure the Docker proxy

Create a directory

mkdir -p /etc/systemd/system/docker.service.d
Copy the code

Configure the agent

cat >/etc/systemd/system/docker.service.d/http-proxy.conf <<EOF [Service] The Environment = "HTTP_PROXY =" http://8.44.151.182:808 "HTTPS_PROXY = http://8.44.151.182:808" "NO_PROXY = localhost, 127.0.0.1, 8.44.169.50 8.44.169.51, 8.44.169.52, 8.44.169.53, 8.44.169.54, 8.44.169.55, cce20120. Certifica tion.com" EOFCopy the code

Restart the service

systemctl daemon-reload 
systemctl restart docker
Copy the code

3. Configure basic mirroring

Pull OS image

docker pull centos:latest
Copy the code

Viewing the Mirror List

docker image ls
Copy the code

Into the mirror

docker run -i -t centos:latest bash
Copy the code

Configure the agent

Export http_proxy = http://8.44.151.182:808 export https_proxy = https://8.44.151.182:808Copy the code

Download basic tools such as network

yum install initscripts
yum install net-tools
Copy the code

4. Installation services

Copy the installation package from the host

Container to the host machine: docker cp mycontainer: / opt/testnew/file. TXT/opt/test/host machine to the container: docker cp /opt/test/file.txt mycontainer:/opt/testnew/Copy the code

Install the necessary service components

yum insall python
Copy the code
yum install zip
Copy the code

Installation business Services

sh vasa_install.sh
Copy the code

5. Submit the container

Once the services inside the container are configured, you can save the container for submission

1. View the task list

docker ps -a
[root@vasa2redhat8 ~]# docker ps -a
CONTAINER ID   IMAGE           COMMAND       CREATED          STATUS                      PORTS     NAMES
14b7945a99eb   centos:latest   "bash"        43 minutes ago   Up 43 minutes                         vasa2
ce380e7331d1   300e315adb2f    "/bin/bash"   46 minutes ago   Exited (0) 46 minutes ago             unruffled_hodgkin
6569482abaa0   300e315adb2f    "/bin/bash"   46 minutes ago   Exited (0) 46 minutes ago             tender_lichterman
b36254a2e46d   300e315adb2f    "/bin/bash"   46 minutes ago   Exited (0) 46 minutes ago             funny_austin
Copy the code

2. Submit the container using the container ID returned above

docker commit -m "vasa2 init" 14b7945a99eb huyan/vasa_container
Copy the code

3. Save the image online (docker warehouse needs to be configured and forbidden by the company)

Log in to the Docker repository

docker login
Copy the code

Submit the container

docker push huyan/vasa_container
Copy the code

4. Save the image offline

docker save -o vasa.tar huyan/vasa_container
Copy the code

The compressed image file is generated in the current directory

6. Container use

Now that the container has been made, how do WE use and publish our image

1. Pull down the online container directly

docker pull vasa:lastest
Copy the code

2. You need to manually upload offline containers to the server and use them after importing them

Docker import va.tar imvasa # build image based on tar exported from containerCopy the code

3. After the image is imported, check that the image is successfully imported and available

[root@vasa2redhat8 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE imvasa latest 0267fe7acea4 10 minutes ago 2.81GB Huyan/Vasa_Container Latest B06f57C11253 18 hours ago 2.79GB < None > < None > 6d514EFF6d5d 18 hours ago 2.79GB centos latest 300e315adb2f 4 months ago 209MBCopy the code

Q&A

1. The local mirror push fails

As a result of the company’s prohibition of docker Hub warehouses, self-built warehouses can be used

2. The container does not run the service command

If necessary dependent packages are not available, install them

yum install initscripts
Copy the code

3. Some commands in the container cannot be executed, for example, systemctl

Probably due to a lack of access,

Start with privilege parameters

dockerun --privileged -itd --name vasa2
Copy the code

4. Docker installation fails

The previous version may cause uninstallation

yum remove docker
yum install docker-ce docker-ce-cli containerd.io
Copy the code