Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker Foundation

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Docker Foundation 1 (basic configuration) 1. Configure docker0 ip address

Root@Userver01:~# cat / etc/docker/daemon.json

{

"bip": "172.16.10.1Accord 24"

}

Root@Userver01:~# systemctl restart docker.service

Root@Userver01:~# ip add l

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1

Link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

Inet 127.0.0.1/8 scope host lo

Valid_lft forever preferred_lft forever

Inet6:: 1/128 scope host

Valid_lft forever preferred_lft forever

2: ens32: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

Link/ether 00:0c:29:cd:a0:83 brd ff:ff:ff:ff:ff:ff

Inet 172.16.251.131/24 brd 172.16.251.255 scope global ens32

Valid_lft forever preferred_lft forever

Inet6 fe80::20c:29ff:fecd:a083/64 scope link

Valid_lft forever preferred_lft forever

3: docker0: mtu 1500 qdisc noqueue state DOWN group default

Link/ether 02:42:80:e8:b3:52 brd ff:ff:ff:ff:ff:ff

Inet 172.16.10.1/24 brd 172.16.10.255 scope global docker0

Valid_lft forever preferred_lft forever

2. Configure docker accelerator

Root@Userver01:~# cat / etc/docker/daemon.json

{

"bip": "172.16.10.1Accord 24"

"registry-mirrors": ["http://5dd4061a.m.daocloud.io"]"

}

Root@Userver01:~# systemctl restart docker.service

Root@Userver01:~# docker info

Containers: 0

Running: 0

Paused: 0

Stopped: 0

Images: 0

Server Version: 18.09.0

Storage Driver: overlay2

Backing Filesystem: extfs

Supports d_type: true

Native Overlay Diff: true

Logging Driver: json-file

Cgroup Driver: cgroupfs

Plugins:

Volume: local

Network: bridge host macvlan null overlay

Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog

Swarm: inactive

Runtimes: runc

Default Runtime: runc

Init Binary: docker-init

Containerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39

Runc version: 4fc53a81fb7c994640722ac585fa9ca548971871

Init version: fec3683

Security Options:

Apparmor

Seccomp

Profile: default

Kernel Version: 4.4.0-131-generic

Operating System: Ubuntu 16.04.5 LTS

OSType: linux

Architecture: x86_64

CPUs: 8

Total Memory: 15.65GiB

Name: Userver01

ID: NB22:HKEI:YEOY:A2F4:TXZP:GEQO:OUME:CT4M:ENYA:VWIM:XXHG:KVK5

Docker Root Dir: / var/lib/docker

Debug Mode (client): false

Debug Mode (server): false

Registry: https://index.docker.io/v1/

Labels:

Experimental: false

Insecure Registries:

127.0.0.0/8

Registry Mirrors:

Http://5dd4061a.m.daocloud.io/

Live Restore Enabled: false

Product License: Community Engine

WARNING: No swap limit support

3. Configure the docker service log format

Root@Userver01:~# cat / etc/docker/daemon.json

{

"bip": "172.16.10.1Accord 24"

"registry-mirrors": ["http://5dd4061a.m.daocloud.io"],"

"log-driver": "journald"

}

Root@Userver01:~# systemctl restart docker.service

Root@Userver01:~# journalctl-xe _ SYSTEMD_UNIT=docker.service

Nov 26 16:40:20 Userver01 dockerd [1979]: time= "2018-11-26T16:40:20.462003344+08:00" level=info msg= "Loading containers: start."

Nov 26 16:40:20 Userver01 dockerd [1979]: time= "2018-11-26T16:40:20.630612895+08:00" level=info msg= "Loading containers: done."

Nov 26 16:40:20 Userver01 dockerd [1979]: time= "2018-11-26T16:40:20.678251298+08:00" level=info msg= "Docker daemon" commit=4d60db4 graphdriver (s) = o

Nov 26 16:40:20 Userver01 dockerd [1979]: time= "2018-11-26T16:40:20.678752739+08:00" level=info msg= "Daemon has completed initialization"

4. Configure docker dns

Root@Userver01:~# cat / etc/docker/daemon.json

{

"bip": "172.16.10.1Accord 24"

"registry-mirrors": ["http://5dd4061a.m.daocloud.io"],"

"log-driver": "journald"

"dns": ["223.5.5.5", "223.6.6.6"]

}

Root@Userver01:~# systemctl restart docker.service

5. Run the container

Root@Userver01:~# docker run-d nginx:1.15

Unable to find image 'nginx:1.15' locally

1.15: Pulling from library/nginx

A5a6f2f73cd8: Pull complete

67da5fbcb7a0: Pull complete

E82455fa5628: Pull complete

Digest: sha256:372965e4f3a1d60ec5be171f839dfe9f8ea076700144f042bae87700a20c9ded

Status: Downloaded newer image for nginx:1.15

246b049b64e32ef924e30a0d614537061cf12a8d1a0408f469dbcf1030c0d554

Root@Userver01:~# docker ps-a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

246b049b64e3 nginx:1.15 "nginx-g'daemon of..." 22 seconds ago Up 21 seconds 80/tcp xenodochial_swirles

6. Log in to the container system

Root@Userver01:~# docker exec-it 246 / bin/bash

Root@246b049b64e3:/# cat / etc/resolv.conf

Search localdomain

Nameserver 223.5.5.5

Nameserver 223.6.6.6

Docker Foundation II (Container Management) 1. Run Container

# start a httpd container to run in the background and map its port 80 to host port 80

Root@Userver01:~# docker run-d-p 80:80 httpd

Unable to find image 'httpd:latest' locally

Latest: Pulling from library/httpd

A5a6f2f73cd8: Already exists

Ac13924397e3: Pull complete

91b81769f14a: Pull complete

Fec7170426de: Pull complete

992c7790d5f3: Pull complete

Digest: sha256:63dba1dad8fe8a920226a631f8189d736b4a5129c2d2edc046a46f36ffc0091c

Status: Downloaded newer image for httpd:latest

B911f2812e516b140f69f412923264670074ec83e4b7aef186041f0e40d57cd4

Root@Userver01:~# docker ps-a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

B911f2812e51 httpd "httpd-foreground" 42 seconds ago Up 41 seconds 0.0.0.0 seconds ago Up 80-> 80/tcp modest_vaughan

# start a container of ubuntu 16.04and exit after printing "hello world"

Root@Userver01:~# docker run ubuntu:16.04 / bin/echo "hello world."

Unable to find image 'ubuntu:16.04' locally

16.04: Pulling from library/ubuntu

7b8b6451c85f: Pull complete

Ab4d1096d9ba: Pull complete

E6797d1788ac: Pull complete

E25c5c290bde: Pull complete

Digest: sha256:e547ecaba7d078800c358082088e6cc710c3affd1b975601792ec701c80cdd39

Status: Downloaded newer image for ubuntu:16.04

Hello world.

Root@Userver01:~# docker ps-a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

4683e7b221b7 ubuntu:16.04 "/ bin/echo 'hello wo..." 28 seconds ago Exited (0) 27 seconds ago pedantic_swirles

B911f2812e51 httpd "httpd-foreground" 3 minutes ago Up 3 minutes 0.0.0.0 minutes ago Up 80-> 80/tcp modest_vaughan

2. Description of the startup process of the container:

Check whether the specified image exists locally, and if not, download it from the specified repository

Use the image to start a container

Assign a file system and mount a read-write layer outside the read-only mirror layer

Bridge a virtual interface to the container from the host configured bridge interface

Configure an IP from the address pool to the container

Execute the program specified by the user

Stop the container after execution

3. Description of common options for docker run

-t: configure a pseudo terminal and bind it to the standard input of the container

-I: keep the standard input of the container open

-d: put the container into the background to run

-c: specifies the cpu shard to which the container is assigned

-m: specifies the amount of memory allocated to the container, in BMagens, Kpas, M, G

4. View the container status on the current node

Docker ps # View currently running containers

Options:

-a: view all containers, including stopped

-Q: show only container ID

-l: displays the last created container

Root@Userver01:~# docker ps-a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

A5a204b817cc ubuntu:16.04 "/ bin/bash" 9 minutes ago Exited (0) 9 minutes ago gifted_tereshkova

4683e7b221b7 ubuntu:16.04 "/ bin/echo 'hello wo..." 18 minutes ago Exited (0) 18 minutes ago pedantic_swirles

B911f2812e51 httpd "httpd-foreground" 21 minutes ago Up 21 minutes 0.0.0.0 minutes ago Up 80-> 80/tcp modest_vaughan

Root@Userver01:~# docker ps-Q

B911f2812e51

Root@Userver01:~# docker ps-qa

A5a204b817cc

4683e7b221b7

B911f2812e51

Root@Userver01:~# docker ps-ql

A5a204b817cc

5. Enter the container

Docker exec-it / bin/bash

Root@Userver01:~# docker ps-qa

A5a204b817cc

4683e7b221b7

B911f2812e51

Root@Userver01:~# docker exec-it B9 / bin/bash

Root@b911f2812e51:/usr/local/apache2#

6. Containers can be roughly divided into two categories according to their uses:

Service containers, such as webserver, database, etc.

Utility containers, such as curl containers, redis-cli containers, etc.

7. Start and stop operation of container

# creation of container:

Docker create

# Startup of container:

Docker start

# stop the container:

Docker stop

Docker kill

# restart the container:

Docker restart

# deletion of container:

Docker rm

Options:

-f: forcibly terminate and delete a running container

-v: delete the data volume mounted by the container

# pause the container:

Docker pause

# resume from pause:

Docker unpause

8. Container life cycle management

9. Container resource restrictions

Memory limit

-m: the amount of memory allowed to be allocated

-- memory-swap: the total amount of memory and swap allowed to be allocated

-- memory-swapiness: controls the ratio of memory to swap replacement

Start a ubuntu container, limit memory to 200m, and the sum of memory and swap is 300m:

Docker run-it-m 200m-- memory-swap 300m ubuntu:16.04

CPU restriction

Docker can set the weight of the cpu used by the container with-c or-- cpu-shares. If not specified, the default is 1024

Docker run-name container_A-c 1024 ubuntu

Docker run-name container_B-c 512 ubuntu

Container_A 's cpu share 1024 is twice that of container_B. When both containers require CPU resources, container_A can get twice as much CPU as container_B.

Io restriction

-- device-read-bps, which restricts reading the bps of a device.

-- device-write-bps, which restricts writing to the bps of a device.

-- device-read-iops, which restricts reading the iops of a device.

-- device-write-iops, which restricts writing to the iops of a device.

# create a container with a limit of 30m bps

Docker run-it-- device-write-bps / dev/sda:30MB ubuntu

Docker Foundation II (Image Management) 1. Image naming

A complete image name:

[Docker Registry address /] [project directory /]: [label]

Example:

Mysql:5.6

Ubuntu

Hub.docker.com/library/centos:6.6

2. Obtain the image

Root@Userver01:~# docker pull ubuntu:16.04

16.04: Pulling from library/ubuntu

7b8b6451c85f: Already exists

Ab4d1096d9ba: Already exists

E6797d1788ac: Already exists

E25c5c290bde: Already exists

Digest: sha256:e547ecaba7d078800c358082088e6cc710c3affd1b975601792ec701c80cdd39

Status: Downloaded newer image for ubuntu:16.04

3. View image information

Root@Userver01:~# docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE

Ubuntu 16.04 a51debf7e1eb 7 days ago 116MB

Nginx 1.15 e81eb098537d 10 days ago 109MB

Httpd latest 2a51bb06dc8b 11 days ago 132MB

Centos 6.6 4e1ad2ce7f78 6 weeks ago 203MB

Root@Userver01:~# docker inspect a51

[

{

"Id": "sha256:a51debf7e1eb2018400cef1e4b01f2e9f591f6c739de7b5d6c142f954f3715a7"

"RepoTags": [

"ubuntu:16.04"

]

"RepoDigests": [

"ubuntu@sha256:e547ecaba7d078800c358082088e6cc710c3affd1b975601792ec701c80cdd39"

]

"Parent":

"Comment":

"Created": "2018-11-19T21:23:53.455319926Z"

"Container": "f4879d05f303ba132b6cc82988306e44819b9d0872dc891d864374d3a9b51b08"

"ContainerConfig": {

"Hostname": "f4879d05f303"

"Domainname":

"User":

"AttachStdin": false

"AttachStdout": false

"AttachStderr": false

"Tty": false

"OpenStdin": false

"StdinOnce": false

"Env": [

"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

]

"Cmd": [

"/ bin/sh"

"- c"

"# (nop)"

"CMD [\" / bin/bash\ "]"

]

"ArgsEscaped": true

"Image": "sha256:d6ab6854552cda39995558786e1690e20092af93f8145294473ac62fd76c9b1b"

"Volumes": null

"WorkingDir":

"Entrypoint": null

"OnBuild": null

"Labels": {}

}

"DockerVersion": "17.06.2-ce"

"Author":

"Config": {

"Hostname":

"Domainname":

"User":

"AttachStdin": false

"AttachStdout": false

"AttachStderr": false

"Tty": false

"OpenStdin": false

"StdinOnce": false

"Env": [

"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

]

"Cmd": [

"/ bin/bash"

]

"ArgsEscaped": true

"Image": "sha256:d6ab6854552cda39995558786e1690e20092af93f8145294473ac62fd76c9b1b"

"Volumes": null

"WorkingDir":

"Entrypoint": null

"OnBuild": null

"Labels": null

}

"Architecture": "amd64"

"Os": "linux"

"Size": 116379573

"VirtualSize": 116379573

"GraphDriver": {

"Data": {

"LowerDir": "/ var/lib/docker/overlay2/d24cfbca95c7fb4a2653aed1fef5e854164d5e452ec1ca1f08d256a841ec9cbe/diff:/var/lib/docker/overlay2/1bc9dd6a582662525ae316dca49703acbcc8087c0549354c622cd0c4eb7095de/diff:/var/lib/docker/overlay2/402ffcd593a76628eb8f3b6dd843b195396729227e55c51c896089ca668770ef/diff"

"MergedDir": "/ var/lib/docker/overlay2/6f5f819b34a36a3cd93e84d2a12a86a3e61f5663a7401ae73cd308211cc3329f/merged"

"UpperDir": "/ var/lib/docker/overlay2/6f5f819b34a36a3cd93e84d2a12a86a3e61f5663a7401ae73cd308211cc3329f/diff"

"WorkDir": "/ var/lib/docker/overlay2/6f5f819b34a36a3cd93e84d2a12a86a3e61f5663a7401ae73cd308211cc3329f/work"

}

"Name": "overlay2"

}

"RootFS": {

"Type": "layers"

"Layers": [

"sha256:41c002c8a6fd36397892dc6dc36813aaa1be3298be4de93e4fe1f40b9c358d99"

"sha256:647265b9d8bc572a858ab25a300c07c0567c9124390fd91935430bf947ee5c2a"

"sha256:819a824caf709f224c414a56a2fa0240ea15797ee180e73abe4ad63d3806cae5"

"sha256:3db5746c911ad8c3398a6b72aa30580b25b6edb130a148beed4d405d9c345a29"

]

}

"Metadata": {

"LastTagTime": "0001-01-01T00:00:00Z"

}

}

]

4. Create a tag for the image

Root@Userver01:~# docker tag ubuntu:16.04 dl.dockerpool.com/library/ubuntu:16.04v1

Root@Userver01:~# docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE

Dl.dockerpool.com/library/ubuntu 16.04v1 a51debf7e1eb 7 days ago 116MB

Ubuntu 16.04 a51debf7e1eb 7 days ago 116MB

Nginx 1.15 e81eb098537d 10 days ago 109MB

Httpd latest 2a51bb06dc8b 11 days ago 132MB

Centos 6.6 4e1ad2ce7f78 6 weeks ago 203MB

5. Search for images

Root@Userver01:~# docker search mysql

NAME DESCRIPTION STARS OFFICIAL AUTOMATED

Mysql MySQL is a widely used, open-source relation... 7407 [OK]

Mariadb MariaDB is a community-developed fork of MyS... 2376 [OK]

Mysql/mysql-server Optimized MySQL Server Docker images. Create... 552 [OK]

Zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 145 [OK]

Hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 102

Zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi... 77 [OK]

Centurylink/mysql Image containing mysql. Optimized to be link... 59 [OK]

1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 47 [OK]

6. Delete the image (Note: if the image is generated by a container, you need to delete the container first)

# if a mirror has multiple tag, only the specified tag will be deleted, but the image itself will not be deleted. If the image ID is specified after the docker rmi, all tag will be deleted

Root@Userver01:~# docker rmi dl.dockerpool.com/library/ubuntu:16.04v1

Untagged: dl.dockerpool.com/library/ubuntu:16.04v1

Root@Userver01:~# docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE

Ubuntu 16.04 a51debf7e1eb 7 days ago 116MB

Nginx 1.15 e81eb098537d 10 days ago 109MB

Httpd latest 2a51bb06dc8b 11 days ago 132MB

Centos 6.6 4e1ad2ce7f78 6 weeks ago 203MB

Root@Userver01:~# docker rmi ubuntu:16.04

Error response from daemon: conflict: unable to remove repository reference "ubuntu:16.04" (must force)-container 4683e7b221b7 is using its referenced image a51debf7e1eb

Root@Userver01:~# docker rmi ubuntu:16.04-f

Untagged: ubuntu:16.04

Untagged: ubuntu@sha256:e547ecaba7d078800c358082088e6cc710c3affd1b975601792ec701c80cdd39

Deleted: sha256:a51debf7e1eb2018400cef1e4b01f2e9f591f6c739de7b5d6c142f954f3715a7

Root@Userver01:~# docker ps-a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

A5a204b817cc a51debf7e1eb "/ bin/bash" About an hour ago Exited (0) About an hour ago gifted_tereshkova

4683e7b221b7 a51debf7e1eb "/ bin/echo 'hello wo..." About an hour ago Exited (0) About an hour ago pedantic_swirles

B911f2812e51 httpd "httpd-foreground" About an hour ago Up About an hour 0.0.0.0 About an hour ago Up About an hour 80-> 80/tcp modest_vaughan

Root@Userver01:~# docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE

Nginx 1.15 e81eb098537d 10 days ago 109MB

Httpd latest 2a51bb06dc8b 11 days ago 132MB

Centos 6.6 4e1ad2ce7f78 6 weeks ago 203MB

# Delete untagged image (i.e. none)

Root@Userver01:~# docker rmi $(docker images-Q-- filter "dangling=true")

7. Export and load images

Root@Userver01:~# docker save-o ubuntu_16.04.tar ubuntu:16.04

Root@Userver01:~# docker rmi ubuntu:16.04-f

Untagged: ubuntu:16.04

Deleted: sha256:a51debf7e1eb2018400cef1e4b01f2e9f591f6c739de7b5d6c142f954f3715a7

Root@Userver01:~# docker load-input ubuntu_16.04.tar

Loaded image: ubuntu:16.04

8. Submit a new image via docker commit

Docker commit-m "change httpd.conf file"-a "john" b911f2812e51 test # uses the b911f2812e51 container to generate an image called test

-a: specify the author

-m: related description information

-p: pauses the container on submission

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report