Docker introduction

The open source application container engine is based on the Go language and complies with the Apache2.0 protocol

Developers package their applications and dependencies into a lightweight, portable container and distribute them to any popular Linux machine

Containers are completely sandboxed and have no interface with each other

Very low container performance overhead

CE (Community Edition) and EE (Enterprise Edition)

Docker application scenario

Automated packaging and distribution of Web applications

Automated testing and continuous integration, release.

The advantages of the Docker

Deliver your applications quickly and consistently

Continuous integration and Continuous delivery (CI/CD) workflowsCopy the code

Reactive deployment and scaling run more workloads on the same hardware

Docker architecture

Three basic concepts:

Image class Container instance RepositoryCopy the code

Client-server (C/S) architectural pattern that uses remote apis to manage and create Docker containers

Install Docker Engine-Community with Docker repository

Set up the warehouse

Install yum – config – manager

[root@master ~]# yum install -y yum-utils \
>   device-mapper-persistent-data \
>   lvm2
Copy the code

Add Aliyun Docker warehouse

[root@master ~]# yum-config-manager \> - add - repo \ > http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo loaded plug-ins: fastestmirror adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repoCopy the code

Install the Docker Engine – Community

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

Lists and sorts the versions available in your repository

yum list docker-ce --showduplicates | sort -r
Copy the code

Start the docker

systemctl start docker
Copy the code

Run the Hello-world image to verify that the installation is correct

docker run hello-world
Copy the code

Mirror to accelerate

Because ali Cloud image was selected during the installation, it has been configured by default. If not, configure it as follows:

{"registry-mirrors":["https://reg-mirror.qiniu.com/"]} systemctl daemon-reload systemctl restart dockerCopy the code

Docker use

Hello World

[root@master docker]# docker run Ubuntu :15.10 /bin/echo "Hello world"
Hello world
Copy the code

Parameter analysis:

Docker: binary execution file of docker.

Run: Combined with the previous Docker to run a container.

Ubuntu :15.10 Specify the image to run, localhost ———— image repository Docker Hub

/bin/echo “Hello world”: the command is executed in the started container

Run interactive containers

[root@master docker]# docker run -i -t Ubuntu :15.10 /bin/bash root@1c52c1d5eff1:/#Copy the code

Parameter analysis:

-t: specifies a dummy terminal or terminal in the new container.

-I: allows you to interact with standard input (STDIN) inside the container.

Run the exit command or CTRL+D to exit the container

Start the container (background mode)

[root@master docker]# docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
3b6b2877b71748220b8acca988d04821c7b0f0ff16c664200d6b272d30f772a7
Copy the code

The container ID is unique to each container

See what happens to the container by container ID

Docker ps views running containers

[root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3b6b2877b717 Ubuntu :15.10 "/bin/sh - c 'while t..." About a minute ago Up About a minute thirsty_mahaviraCopy the code

Output details:

CONTAINER ID: indicates the ID of a CONTAINER. IMAGE: IMAGE used. COMMAND: The COMMAND that is run when the container is started. CREATED: time when the container was CREATED. STATUS: indicates the STATUS of the container. Created restarting Running or Up Removing Removing paused exited Dead PORTS: Created restarting Running removing removing paused exited Dead PORTS: The port information of the container and the connection type used (TCP \ UDP). NAMES: automatically assigned container NAMES.Copy the code

Docker logs view standard output within the container

[root@master docker]# docker logs 3b6b2877b717
hello world
hello world
hello world
...
Copy the code

Docker stop Stops the container

[root@master docker]# docker stop 3b6b2877b717
3b6b2877b717
Copy the code

The client

Enter the Docker command directly to view all command options of the Docker client

[root@master docker]# docker

Usage:  docker [OPTIONS] COMMAND
...
Copy the code

Docker command –help to learn more about how to use the specified docker command

[root@master docker]# docker stats --help Usage: docker stats [OPTIONS] [CONTAINER...]  Display a live stream of container(s) resource usage statistics Options: -a, --all Show all containers (default shows just running) --format string Pretty-print images using a Go template --no-stream Disable streaming stats and only pull the first result --no-trunc Do not truncate outputCopy the code

containers

Access to the mirror

[root@master docker]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
Digest: sha256:c95a8e48bf88e9849f3e0f723d9f49fa12c5a00cfc6e60d2bc99d87555295e4c
Status: Image is up to date for ubuntu:latest
docker.io/library/ubuntu:latest
Copy the code

Start the container

[root@master docker]# docker run -it ubuntu /bin/bash
root@b9f8b5d3ce5f:/#
Copy the code

Start a stopped container

Docker ps -a view all containers

[root@master docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b9f8b5d3ce5f ubuntu "/bin/bash"  About a minute ago Exited (127) 3 seconds ago friendly_satoshi ...Copy the code

Docker start Starts a stopped container

[root@master docker]# docker start b9f8b5d3ce5f
b9f8b5d3ce5f
Copy the code

The background

If -d is added, it will not enter the container by default. Docker exec is required to enter the container

[root@master docker]# docker run -itd --name ubuntu-test ubuntu /bin/bash
6674e565ca1e4d720269045c2c166286cfe16c2b6649268edc680e4fb8b1943f
Copy the code

Stop and restart the container

Docker stop < container ID> Stops the container

[root@master docker]#  docker stop b9f8b5d3ce5f
b9f8b5d3ce5f
Copy the code

Docker restart < container ID> Restart the container

[root@master docker]# docker restart b9f8b5d3ce5f
b9f8b5d3ce5f
Copy the code

Into the container

The attach command

Exiting from the container causes the container to stop

[root@master docker]#  docker attach b9f8b5d3ce5f
root@b9f8b5d3ce5f:/#
Copy the code

The exec command

Exit the container, the container will not stop

[root@master docker]# docker exec -it b9f8b5d3ce5f  /bin/bash
root@b9f8b5d3ce5f:/#
Copy the code

Export container

 docker export b9f8b5d3ce5f  > ubuntu.tar
Copy the code

Import the container

[root@master docker]# cat ubuntu.tar | docker import - test/ubuntu:v1
sha256:10f9c3548de8204d30181945984d7ad16845cc0db6d3df79886b084bcd40eace
[root@master docker]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED              SIZE
test/ubuntu       v1        10f9c3548de8   About a minute ago   72.9MB
Copy the code

Remove the container

Delete the < container ID> container

[root@master docker]# docker rm -f b9f8b5d3ce5f
b9f8b5d3ce5f
Copy the code

Clean up terminated containers

[root@master docker]# docker container prune WARNING! This will remove all stopped containers. Are you sure you want to continue? [y/N] y Deleted Containers: 3b6b2877b71748220b8acca988d04821c7b0f0ff16c664200d6b272d30f772a7 1c52c1d5eff1c84f57bf5490d81049110ad8bf099ca1c4df8e336e46b6be65f5 9b59d67dd00c711d5ff14a4840acffa793a13f04f6b07ace8652727b5a9c387f 201a6a9c7783193ab4e23174b9c7ca2ae5b912ce6df706022e43916c42fd07c0 d6bd823aa49bb8c25e8453b321f0cb9a6087b01c3818e99670d7653e00aa761e 26dd7b28c118c021017f735384d6e426f08cdd18eb3d3c44b10faf28e9d9a479 233d908ca0d7136cf8b440ac8b0cfb08ef3703e23a93f62d7289557dac19f25a 0ea225696075295c73e7d4a154af5feb2c846f6547aa834fd2b47c970bfa9dfb 067294d64005db7ecb2f315fbe0479d306257f29ca5f4d1ab57be4b427539d76 f6f1c1233cc805f23a1ebc1ee9e08a7452986bb178819d84f036ee81a3a0250f 5c6e8b26c3aace09b90ec3940a813a19d7ec2649fefd366ebb2a7b54fbb09236 0813d0b8cc6e5274867b0794cf9c477154581bdc49cc0d581f9586a5e7db08ca 63088 d7b238d363b22db7641f931dc92e5ebca9b65a48b89a0221b0583cc5177 Total reclaimed space: 27.81 MBCopy the code

Run a Web application

Building an
[root@master docker]# docker run -d -p training/ webApp python app.py A79d72088a887e4f8d9895d2f339e670228cabf8892a54e1fd19919819c6d8a # 9 - P: internal use network port random mapped to the container we use hosts [root @ master docker] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9a79d72088a8 training/webapp "python app.py" 2 minutes Nostalgically, ago Up 2 minutes 0.0.0.0:49153->5000/ TCP Rhodes # View WEB application containers Docker Run -d -p 55:5000 training/ webApp Py # -p to set different ports [root@master docker]# docker run -d -p 55:5000 training/ webApp Python app.py e4c3e8ef60343c18d957bd17b0759e968ead423fa9fa1c648c6bee0d69db5692 [root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e4c3e8ef6034 training/webapp "python app.py" 8 seconds ago Up 6 seconds 0.0.0.0:5000 - > 5000 / TCP modest_chaumCopy the code
Access using a browser

View the shortcut to the network port
[root@master docker]# docker port e4c3e8EF6034 5000/ TCP -> 0.0.0.0:5000Copy the code
View WEB application logs
[root@master docker]# docker logs -f e4c3e8EF6034 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) 192.168.108.135 - - [18/Dec/2020 09:31:03] "GET/HTTP/1.1" 200-192.168.108.135 - - [18/Dec/2020 09:31:03] "GET /favicon. Ico HTTP/1.1" 404-192.168.108.135 - - [18/Dec/2020 09:36:16] "GET/HTTP/1.1" 200-192.168.108.135 - - [18/Dec/2020 09:36:19] "GET/HTTP/1.1" 200-192.168.108.135 - - [18/Dec/2020 09:36:29] "GET/HTTP/1.1" 200 -Copy the code
View the processes of the WEB application container
[root@master docker]# docker top e4c3e8ef6034
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                69133               69109               0                   17:30               ?                   00:00:00            python app.py
Copy the code
Check the WEB application

Return a JSON file that records the configuration and status of the Docker container

[root@master docker]# docker inspect e4c3e8ef6034 [ { "Id": "e4c3e8ef60343c18d957bd17b0759e968ead423fa9fa1c648c6bee0d69db5692", "Created": "The T09:2020-12-18 and. 931960826 z", "Path" : "python", "Args" : [" app. Py "...Copy the code
Stop the WEB application container
[root@master docker]# docker stop e4c3e8ef6034
e4c3e8ef6034
Copy the code
Restart the WEB application container
[root@master docker]# docker start e4c3e8ef6034
e4c3e8ef6034
Copy the code
Query the last container created
[root@master docker]# docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e4c3e8ef6034 training/webapp Py "14 minutes ago Up 29 seconds 0.0.0.0:5000->5000/ TCP modest_chaumCopy the code
Remove the WEB application container

When deleting a container, the container must be stopped; otherwise, the following error is reported

[root@master docker]# docker rm  e4c3e8ef6034
Error response from daemon: You cannot remove a running container e4c3e8ef60343c18d957bd17b0759e968ead423fa9fa1c648c6bee0d69db5692. Stop the container before attempting removal or force remove
Copy the code

Remove the WEB application container

[root@master docker]# docker stop e4c3e8ef6034
e4c3e8ef6034
[root@master docker]# docker rm  e4c3e8ef6034
e4c3e8ef6034

Copy the code

Image using

Lists the images on the local host
[root@master docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test/ubuntu v1 10f9c3548de8 About an hour ago 72.9 MBCopy the code

Options:

TAG: indicates the IMAGE TAG. IMAGE ID: indicates the IMAGE ID. CREATED: indicates the time when an IMAGE is CREATED. SIZE: indicates the IMAGE SIZECopy the code

Run the container using the Ubuntu system image version 15.10

Docker run -t -i Ubuntu :15.10 /bin/bashCopy the code
Get a new image
[root@master docker]# docker pull Ubuntu :13.10 13.10: Pulling the from library/ubuntu Image docker. IO/library/ubuntu: 13.10 USES outdated in the manifest format. Do the upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/ a3ed95caeb02: Pull complete 0d8710fc57fd: Pull complete 5037c5cd623d: Pull complete 83b53423b49f: Pull complete e9e8bd3b94ab: Pull complete 7db00e6b6e5e: Pull complete Digest: sha256:403105e61e2d540187da20d837b6a6e92efc3eb4337da9c04c191fb5e28c44dc Status: Downloaded newer image for ubuntu: 13.10 docker. IO/library/ubuntu: 13.10Copy the code
Find the mirror
[root@master docker]# docker search httpd NAME DESCRIPTION STARS OFFICIAL AUTOMATED httpd The Apache HTTP Server Project 3288 [OK] centos/httpd-24-centos7 Platform for running Apache HTTPD 2.4 or bui... 36 centos/httpd 33 [OK] arm32v7/httpd The Apache HTTP Server Project 9 arm64v8/httpd The Apache HTTP Server Project 6 Polinux /httpd-php Apache with PHP in Docker (Supervisor, CentO... 4 [OK] salim1983hoop/httpd24 Dockerfile running apache config 2 [OK] publici/httpd httpd:latest 1 [OK] Solsson/httpD-openIDC mod_auth_openIDC on Official HTTPD Image, VE... 1 [OK] Inanimate /httpd-ssl A play container with HTTPD, SSL enabled, an... 1 [OK] hypoport/httpd-cgi httpd-cgi 1 [OK] dariko/httpd-rproxy-ldap Apache HTTPD Reverse proxy with LDAP authent... 1 [OK] ClearLinux/HTTPD HTTPD HyperText Transfer Protocol (HTTP) ser... Lead4good/httpD-FPM HTTPD server which connects VIA FCGI proxy H... 1 [OK] jonathanheilmann/httpd-alpine-rewrite httpd:alpine with enabled mod_rewrite 1 [OK] appertly/httpd Customized Apache HTTPD that uses a phP-fpm... 0 [OK] amd64/httpd The Apache HTTP Server Project 0 manasip/httpd 0 trollin/httpd 0 interlutions/httpd httpd docker Image with Debian-based config... 0 [OK] e2eteam/httpd 0 manageiq/httpd_configmap_generator Httpd Configmap Generator 0 [OK] itsziget/httpd24 Extended HTTPD Docker Image based on the off... 0 [OK] Manageiq/HTTPD Container with HTTPD, built on CentOS for... 0 [OK] dockerpinata/httpd 0Copy the code

Options:

Docker OFFICIAL docker OFFICIAL docker OFFICIAL docker OFFICIAL docker OFFICIAL docker OFFICIAL docker OFFICIAL docker OFFICIAL docker OFFICIAL docker OFFICIAL docker OFFICIAL docker OFFICIAL docker star AUTOMATED: Automatic construction.Copy the code
Drag take mirror
[root@master docker]# docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
6ec7b7d162b2: Already exists
17e233bac21e: Pull complete
130aad5bf43a: Pull complete
81d0a34533d4: Pull complete
da240d12a8a4: Pull complete
Digest: sha256:a3a2886ec250194804974932eaf4a4ba2b77c4e7d551ddb63b01068bf70f4120
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
Copy the code
Remove the mirror
[root@master docker]#  docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
Deleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63
Copy the code
Create a mirror image

Update the image from the created container and commit the image

[root@master docker]# docker commit -m="has update" -a="runoob" c9ce132a0acd runoob/ubuntu:v2
sha256:62ba08755fc78e28a11f6ebc69ead6974c514a88cf40a8b764d27632f6bcb673
Copy the code

Parameter Description:

-a: Specifies the image author. C9ce132a0acd Container ID Runoob/Ubuntu :v2 Specifies the name of the image to be createdCopy the code

Use the Dockerfile directive to create a new image

[root@master docker]# vim Dockerfile [root@master docker]# cat Dockerfile FROM centos:6.7 MAINTAINER Fisher "[email protected]" RUN /bin/echo 'root:123456' |chpasswd RUN useradd runoob RUN /bin/echo 'runoob:123456' |chpasswd RUN  /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/local EXPOSE 22 EXPOSE 80 CMD /usr/sbin/sshd -D [root@master docker]# Docker build -t runoob/centos:6.7. Sending build context to Docker daemon 75.28MB Step 1/9: FROM centos:6.7 --> 9f1de3c6ad53 Step 2/9: MAINTAINER Fisher "[email protected]" ---> Using cache ---> f14df0b17382 Step 3/9 : RUN /bin/echo 'root:123456' |chpasswd ---> Running in 23cbe37429ee Removing intermediate container 23cbe37429ee ---> 1302fdb3cef6 Step 4/9 : RUN useradd runoob ---> Running in aeb861f2cd4a Removing intermediate container aeb861f2cd4a ---> 3ad14f808f16 Step 5/9 : RUN /bin/echo 'runoob:123456' |chpasswd ---> Running in a342ac1edf83 Removing intermediate container a342ac1edf83 ---> c728d6cdc20e Step 6/9 : RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/local ---> Running in da2f2c973c64 Removing intermediate container  da2f2c973c64 ---> ba76b9c9d0be Step 7/9 : EXPOSE 22 ---> Running in b5b8758aef68 Removing intermediate container b5b8758aef68 ---> de07a8de1322 Step 8/9 : EXPOSE 80 ---> Running in 0a38429cc7f7 Removing intermediate container 0a38429cc7f7 ---> 1d6a78fc769b Step 9/9 : CMD /usr/sbin/sshd -D ---> Running in f0f6a7734d88 Removing intermediate container f0f6a7734d88 ---> 44f4bb339cfa Successfully built 44f4bb339cfa Successfully tagged runoob/centos:6.7Copy the code

FROM specifies which mirror source to use

The RUN command tells Docker to execute commands within the image

Parameter Description:

-t: specifies the name of the target image to be created. : specifies the directory where the Dockerfile file resides. You can specify the absolute path of the DockerfileCopy the code
Setting a Mirror Label
docker tag 44f4bb339cfa  runoob/centos:dev
Copy the code

Container connection

Network Port Mapping

The port mapping is specified with the -p or -p argument

-p: indicates a high-end port randomly mapped from a container port to a host

[root@master docker]# docker run -d -P training/webapp python app.py 85f780a4c7683a67811f3e8fefc09422b53acfaca38705a0f81d2135a474783e [root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 85f780a4c768 training/webapp "python app.py" 14 seconds ago Up 14 seconds 0.0.0.0:49154 - > 5000 / TCP mystifying_goldstineCopy the code

-p: indicates that an internal port in a container is bound to a specified host port.

[root@master docker]# docker run -d -p 5000:5000 training/webapp python app.py ece3ef938f534cb7a344f9e66f92d02a42234d85ab74440f1c0228af45672695 [root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ece3ef938f53 training/webapp "python app.py" 13 seconds ago Up 13 seconds 0.0.0.0:5000 - > 5000 / TCP happy_lamarrCopy the code

Specifies the network address bound to the container

[root@master docker]# docker run -d -p 127.0.0.1:5001:5000 training/ webApp Python app.py 79cf97425fe71708e424dc4d094e8a0484a93273a38c44351a388c8d14e2c704 [root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 79cf97425fe7 training/webapp "python app.py" About a minute ago Up About a minute 127.0.0.1:5001 - > 5000 / TCP sharp_chaumCopy the code

To bind a UDP port, you can add/UDP after the port

[root@master docker]# docker run -d -p 127.0.0.1:55:5000 /udp training/ webApp Python app.py 231e3abd72087afa5b6b6268246800a6df514304f3c202ee0dce86fd48158bf9 [root@master docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 231e3abd7208 training/webapp "python app.py" 14 seconds ago Up 13 seconds 5000/tcp, 127.0.0.1:5000 - > 5000 / udp agitated_jemisonCopy the code

You can quickly view the binding status of ports

[root@master docker]# docker port 79cf97425fe75000 / TCP -> 127.0.0.1:5001Copy the code

The container of interconnected

Vessel named

The –name identifier names the container

[root@master docker]# docker run -d -P --name runoob training/webapp python app.py 2738c8caec5779d2e25d4cf63d5570d4abf29ae6e8f67c742f0e08bc6c3c4fc7 [root@master docker]# docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2738c8caec57 training/webapp "python app.py" 12 seconds ago Up 12 seconds 0.0.0.0:49155 - > 5000 / TCP runoobCopy the code
New network
[root@master docker]# docker network create -d bridge devops
0c566304756424b2d1a5a8c16e0161ab9d318284a69c7e725b6062dd291f54ce
Copy the code

Parameter description: -d: Specifies the Docker network type, including bridge and overlay

Connect the container
[root@master docker]# docker network create -d bridge devops 0c566304756424b2d1a5a8c16e0161ab9d318284a69c7e725b6062dd291f54ce [root@master docker]# docker run -itd --name test1 --network devops ubuntu /bin/bash b17703c752b7ca7586e9dabf4de5bc70b9f04b6062385cb07ac1eef96bad484c [root@master docker]#  docker run -itd --name test2 --network devops ubuntu /bin/bash 1f7b62a4dd45687233eafb6cde6f1f2ce9d57439bcd2c00da41740f6c8ae3914Copy the code
Configure DNS

Set DNS for all containers

[root@master docker]# vim daemon.json [root@master docker]# cat daemon.json {" registry - mirrors ":" https://reg-mirror.qiniu.com/ "]} {" DNS ": [" 114.114.114.114", "8.8.8.8"]}Copy the code

You need to restart the Docker for the configuration to take effect

Check whether the DNS of the container takes effect

[root@master init.d]# docker run -it --rm  ubuntu  cat etc/resolv.conf

nameserver 192.168.108.1
Copy the code

The configuration fails because the configuration file is incorrectly written.

[root@master docker]# vim daemon.json [root@master docker]# cat daemon.json { "Registry - mirrors" : "DNS", "https://reg-mirror.qiniu.com/"/" 114.114.114.114 ", "8.8.8.8"}Copy the code

After configuration, restart docker, error:

[root@master docker]# systemctl restart docker Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details. [root@master docker]# systemctl Service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; Vendor PRESET: disabled) Active: Failed (Result: start-limit) since a 2020-12-21 11:56:06 CST; 10s ago Docs: https://docs.docker.com Process: 6216 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, Status =1/FAILURE) Main PID: 6216 (code=exited, status=1/FAILURE) Failed to start Docker Application Container Engine. 12月 21 11:56:04 Master Systemd [1]: 12月 21 11:56:04 Master Systemd [1]: Docker. service failed. 12月 21 11:56:06 Master Systemd [1]: Scheduling restart. 12月 21 11:56:06 Master Systemd [1]: Stopped Docker Application Container Engine. 12月 21 11:56:06 Master Systemd [1]: If a request is repeated too quickly for a docker.service 12月 21 11:56:06 Master Systemd [1]: Failed to start Docker Application Container Engine. 12月 21 11:56:06 Master Systemd [1]: 12月 21 11:56:06 Master Systemd [1]: Docker. service entered when docker.service failed.Copy the code

Reason daemon.json is wrong, comma missing.

[root@master docker]# cat daemon.json {"registry-mirrors":["https://reg-mirror.qiniu.com/"], # less comma place "DNS ": ["114.114.114.114", "8.8.8.8"]}Copy the code

The effect takes effect after docker is restarted

[root@master docker]# systemctl restart docker
[root@master docker]# docker run -it --rm  ubuntu  cat etc/resolv.conf
nameserver 114.114.114.114
nameserver 8.8.8.8
Copy the code

Manually specify the configuration of the container

[root@master init.d]# docker run it --rm -h host_ubuntu -- DNS =114.114.114.114 --dns-search=test.com ubuntu root@host_ubuntu:/#Copy the code

–rm: Automatically clears the file system inside the container when the container exits.

-h HOSTNAME or — HOSTNAME =HOSTNAME: sets the HOSTNAME of the container, which will be written to /etc/hostname and /etc/hosts in the container.

— DNS =IP_ADDRESS: Add a DNS server to /etc/resolv.conf and let the container use this server to resolve all the host names that are not in /etc/hosts

–dns-search=DOMAIN: Sets the search DOMAIN of the container. When the search DOMAIN is set to.example.com, when searching for a host named host, the DNS searches not only host but also host.example.com.

Warehouse management

Docker officially maintains a public repository Docker Hub.

hub.docker.com

registered

Login and Logout

[root@master docker]# 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: cpyaxjq
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
[root@master docker]# docker logout
Removing login credentials for https://index.docker.io/v1/
Copy the code

Find images in the official repository

[root@master docker]# docker search ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating sys... [OK] Dorowu/Ubuntu-desktop-lxde-VNC Docker Image to provide HTML5 VNC interface... 481 [OK] websphere-Liberty websphere Liberty Multi-Architecture Images... 265 [OK] Rastasheep/Ubuntu-sshd Dockerized SSH Service, Built on Top of Offi... 259 [OK] Consol/ubuntu-xfce-VNC Ubuntu container with "headless" VNC session 228 [OK] Ubuntu -upstart upstart is an event-based replacement for th... 109 [OK] Neurodebian provides neuroscience research s... 77 [OK] 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 50 [OK] Ubuntu - debootstrap debootstrap -- the variant = minbase - components = m... 44 [OK] Open-liberty Open Liberty Multi-architecture Images based on... 40 [OK] NuageBEC/Ubuntu Simple Always updated Ubuntu Docker images W... 24 [OK] i386/ Ubuntu Ubuntu is a debian-based Linux operating system... 12 [OK] 1and1Internet /ubuntu-16-apache-php-7.0 [OK] 1and1Internet/Ubuntu-16-apache-php-7.0 Ubuntu - 16 - apache - PHP - 13 [OK] 1 and1internet/ubuntu 7.0-16 - nginx - PHP - phpmyadmin - mariadb - 10 Ubuntu - 16 - nginx - PHP - phpmyadmin - mariadb - 10 of 11 [OK] 1 and1internet/ubuntu - 16 - nginx - PHP - 5.6 - wordpress - 4 Ubuntu -nginx-php-5.6-wordpress 7 [OK] ubuntu -nginx-php-5.6-wordpress 7 [OK] Ubuntu -nginx-php-5.6-wordpress 7 [OK] ubuntu -nginx-php-5.6-wordpress 7 [OK] ubuntu -nginx-php-5.6-wordpress 7 [OK] darksheer/ubuntu Base Ubuntu Image -- Updated hourly 5 [OK] pivotaldata/ubuntu A quick freshening-up of the base Ubuntu Doc... 4 [OK] PivotalData /ubuntu16.04- Build Ubuntu 16.04 image 4 [OK] PivotalData /ubuntu16.04- Build Ubuntu 16.04 image For GPDB compilation 2 Smartentry/Ubuntu Ubuntu with Smartentry 1 [OK] 1and1Internet/Ubuntu-16-php-7.1 Ubuntu-16-php-7.1 1 [OK] PivotalData /ubuntu-gpdb-dev Ubuntu images for GPDB development 1 [OK] Pivotaldata /ubuntu16.04-test Ubuntu 16.04 image  for GPDB testing 0Copy the code

Docker Pull downloads the official Ubuntu image locally

[root@master docker]#  docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
Digest: sha256:c95a8e48bf88e9849f3e0f723d9f49fa12c5a00cfc6e60d2bc99d87555295e4c
Status: Image is up to date for ubuntu:latest
docker.io/library/ubuntu:latest
Copy the code

Push the mirror

[root@master docker]# Docker image ls REPOSITORY TAG Image ID CREATED SIZE Ubuntu latest f643c72bc252 3 weeks ago 72.9MB [root@master docker]# docker Tag Ubuntu :latest cpyaxjq/ Ubuntu :18.04 [root@master docker]# docker push Cpyaxjq/Ubuntu :18.04 The push refers to repository [docker. IO /cpyaxjq/ Ubuntu]Copy the code

Dockerfile

A Dockerfile is a text file used to build an image. The text content contains the instructions and instructions required to build the image.

ENTRYPOINT ENV ARG VOLUME EXPOSE WORKDIR USER HEALTHCHECK ONBUILDCopy the code

Compose

Compose is a tool for defining and running multi-container Docker applications

Compose uses three steps:

  1. Use Dockerfile to define your application’s environment.

  2. Use docker-comemage.yml to define the services that make up the application so that they can run together in an isolated environment.

  3. Finally, execute the docker-compose up command to get the entire application up and running.

Compose the installation

steps

[root @ master SRC] # curl - L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 651 100 651 00 667 0 --:--:-- --:--:-- --:--:-- 667 30 15.4m 30 4878K 00 3935 0 1:08:28 0:21:09 0:47:19 0 curl: (56) TCP connection reset by peer [root@master src]# chmod +x /usr/local/bin/docker-compose [root@master src]# ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose [root@master src]# docker-compose --version [17111] Cannot open self /usr/local/bin/docker-compose or archive /usr/local/bin/docker-compose.pkgCopy the code

An error was found during installation. The error was caused by incomplete download due to network reasons.

Solution: Use wget download.