systemctl start docker #开启
systemctl stop docker #停止
systemctl restart docker #重启
systemctl enable docker #开机启动
systemctl status docker #查看状态
#查看状态结果演示:running
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2020-02-23 13:59:36 CST; 8min ago
Docs: https://docs.docker.com
Main PID: 11579 (dockerd)
Tasks: 8
Memory: 46.3M
CGroup: /system.slice/docker.service
└─11579 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
2月 23 13:59:35 localhost.localdomain dockerd[11579]: time="2020-02-23T13:59:35.076937797+08:00" le...rpc
2月 23 13:59:35 localhost.localdomain dockerd[11579]: time="2020-02-23T13:59:35.076951996+08:00" le...rpc
2月 23 13:59:35 localhost.localdomain dockerd[11579]: time="2020-02-23T13:59:35.076959177+08:00" le...rpc
2月 23 13:59:35 localhost.localdomain dockerd[11579]: time="2020-02-23T13:59:35.162544901+08:00" le...t."
2月 23 13:59:36 localhost.localdomain dockerd[11579]: time="2020-02-23T13:59:36.329348664+08:00" le...ss"
2月 23 13:59:36 localhost.localdomain dockerd[11579]: time="2020-02-23T13:59:36.829029223+08:00" le...e."
2月 23 13:59:36 localhost.localdomain dockerd[11579]: time="2020-02-23T13:59:36.891769205+08:00" le...3.6
2月 23 13:59:36 localhost.localdomain dockerd[11579]: time="2020-02-23T13:59:36.891982409+08:00" le...on"
2月 23 13:59:36 localhost.localdomain dockerd[11579]: time="2020-02-23T13:59:36.917905174+08:00" le...ck"
2月 23 13:59:36 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
docker images 查看本地镜像
docker images -q 查看本地所有镜像的ID
docker search 在线搜索镜像
docker pull 下载拉取镜像
docker pull mysql:5.5 下载指定版本的镜像
docker rmi 删除本地镜像
docker rmi `docker images -q`删除本地所有镜像
docker info 守护进程的系统资源设置
[root@pokes03 ~]# docker info
Client:
Debug Mode: false
Server:
Containers: 2
Running: 2 #运行的容器数量
Paused: 0
Stopped: 0
Images: 4 #共有几个镜像
Server Version: 19.03.11 #docker版本
Storage Driver: overlay2 #存储驱动,如果你的这里是dm说明你的内核版本太低。overlay远比dm强大
Backing Filesystem: xfs #文件系统
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan 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: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1127.8.2.el7.x86_64 #内核版本
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 468.4MiB #资源数
Name: pokes03
ID: J2RQ:MO7G:TEZO:UIRQ:NJDJ:XCSH:X7MN:KYJE:BBOE:GP5F:WT4S:HVOE
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://tue4pc99.mirror.aliyuncs.com/ #加速的镜像站点
Live Restore Enabled: false
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
以上你只需要注意你的存储驱动即可,其他都只是了解
[root@pokes03 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
镜像名称 版本 镜像ID 创建时间 大小
wordpress latest 2c9350d16623 4 days ago 540MB
nginx latest 2622e6cca7eb 6 days ago 132MB
mysql 5.7 9cfcce23593a 7 days ago 448MB
mysql 5.5 d404d78aa797 13 months ago 205MB
docker images -q #查看本地所有镜像的ID
[root@localhost ~]# docker images -q
d404d78aa797
NAME(名称), DESCRIPTION(描述),STARS(点赞数)
OFFICIAL(是否官方),AUTOMATED(是否自动流程构建)
[root@localhost ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 9152 [OK]
mariadb MariaDB is a community-developed fork of MyS… 3248 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 676 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 69
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 62
centurylink/mysql Image containing mysql. Optimized to be link… 61 [OK]
deitch/mysql-backup REPLACED! Please use http://hub.docker.com/r… 41 [OK]
bitnami/mysql Bitnami MySQL Docker Image 36 [OK]
tutum/mysql Base docker image to run a MySQL database se… 34
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 29 [OK]
prom/mysqld-exporter 26 [OK]
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 24
centos/mysql-56-centos7 MySQL 5.6 SQL database server 19
circleci/mysql MySQL is a widely used, open-source relation… 18
mysql/mysql-router MySQL Router provides transparent routing be… 14
arey/mysql-client Run a MySQL client from a docker container 13 [OK]
databack/mysql-backup Back up mysql databases to... anywhere! 10
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 5 [OK]
genschsa/mysql-employees MySQL Employee Sample Database 4 [OK]
devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici… 2
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
jelastic/mysql An image of the MySQL database server mainta… 1
monasca/mysql-init A minimal decoupled init container for mysql 0
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 0 [OK]
[root@localhost ~]#
除了上面的方法搜索镜像之外,你还可以访问官网:hub.docker.com
[root@localhost ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
619014d83c02: Pull complete
9ced578c3a5f: Pull complete
731f6e13d8ea: Pull complete
3c183de42679: Pull complete
6de69b5c2f3c: Pull complete
122a561a4196: Pull complete
1abf8e9f34f0: Pull complete
1e5887414166: Pull complete
95adaca07078: Pull complete
42c8c6542347: Pull complete
0ae93d9077ae: Pull complete
42131d6ef54e: Pull complete
Digest: sha256:c7c6c5beb312fd2eb21af4f144d14b6ef29c9c2f9c5e1f3f74ffa75e38fad1f4
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest afaec1334369 2 days ago 471MB
docker pull mysql这样下载的是mysql的最新版——latest,可是我不想要最新版,我就想要mysql5.5版本。怎么办呢?
方法一:
命令:docker pull mysql:5.5 英文冒号
docker pull mysql:5.5 #下载指定版本,下载前线查询一下有没有
#先查看一下有没有mysql5.5
[root@localhost ~]# docker search mysql5.5
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
micktwomey/mysql5.5 1 [OK]
717160040/mysql5.5 MySQL5.5root带远程连接权限 1
andreiqw/mysql5.5.22 mysql 5.5.22 based on debian:jessie. Repo: h… 0
gaumire/mysql5.5 Custom MySQL image version 5.5. 0
phox/mysql5.5 0 [OK]
jmw1/mysql5.5 Default .cnf MySQL Server 0
prodaptimages/mysql5.5 0
shrebo/mysql5.5 0
etsbim/mysql5.5 0
lopydev/mysql5.5 mysql5.5 0
pengfeifan/mysql5.5.53 0
jiezhiz/mysql5.5 0
smartatech/mysql5.5 0
adolgarev/mysql5.5 0
461525162/mysql5.5 mysql 5.5 for centos7 0
kyawphyonaing/mysql5.5 0
vikasmunjal25/mysql5.5 0
cwa302/mysql5.5 0
lujieni/mysql5.5 0
luohua2018/mysql5.5 0
zm274310577/mysql5.5 0
silkesrp/mysql5.5.55 0
maitarek/mysql5.5 0
alcionemorais/mysql5.5 Instala mysql5.5 0
gilra200/mysql5.5 0
#下载mysql:5.5
[root@localhost ~]# docker pull mysql:5.5
5.5: Pulling from library/mysql
743f2d6c1f65: Pull complete
3f0c413ee255: Pull complete
aef1ef8f1aac: Pull complete
f9ee573e34cb: Pull complete
3f237e01f153: Pull complete
03da1e065b16: Pull complete
04087a801070: Pull complete
7efd5395ab31: Pull complete
1b5cc03aaac8: Pull complete
2b7adaec9998: Pull complete
385b8f96a9ba: Pull complete
Digest: sha256:12da85ab88aedfdf39455872fb044f607c32fdc233cd59f1d26769fbf439b045
Status: Downloaded newer image for mysql:5.5
docker.io/library/mysql:5.5
#下载成功
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest afaec1334369 2 days ago 471MB
mysql 5.5 d404d78aa797 9 months ago 205MB
方法二:
打开 https://hub.docker.com 搜索 ,之后下载,好了之后上传到centos中docker的镜像目录,详细的这里就不介绍了。只给大家说一下上传到哪个目录。使用docker info命令可以查看镜像信息,信息如下:
[root@localhost ~]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 2
Server Version: 19.03.6
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan 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: b34a5c8af56e510852c35414db4c1f4fa6172339
runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1062.12.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 972.4MiB
Name: localhost.localdomain
ID: IONN:BK4R:FIU5:IDDZ:6OE4:SVUF:IOF6:BGBO:FD2R:OHMZ:FDOZ:ZIZO
Docker Root Dir: /var/lib/docker <——————镜像目录
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://tue4pc99.mirror.aliyuncs.com/
Live Restore Enabled: false
我们可以看到 /var/lib/docker<——————镜像目录,上传到这里就可以了。
docker rmi 镜像ID/名称和版本号
例如:我现在不想要mysql最新版,只留下mysql5.5
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest afaec1334369 2 days ago 471MB
mysql 5.5 d404d78aa797 9 months ago 205MB
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest afaec1334369 2 days ago 471MB
mysql 5.5 d404d78aa797 9 months ago 205MB
[root@localhost ~]# docker rmi afaec1334369
Error response from daemon: invalid reference format
这里报错说是:守护进程的错误响应:无效的引用格式,那我们通过版本号删除
[root@localhost ~]# docker rmi mysql:latest
Untagged: mysql:latest
Untagged: mysql@sha256:c7c6c5beb312fd2eb21af4f144d14b6ef29c9c2f9c5e1f3f74ffa75e38fad1f4
Deleted: sha256:afaec1334369d4bb6fe566f3f3d4b075ed4b74a6fcba61f9740aee4715888b21
Deleted: sha256:2e6c9aa9d020930f5cd87642a6b1301b0fb6530541ad2c1307f6a5a7c6be2bf8
Deleted: sha256:12cc75beecacd8f363465aaf4dba0c6af62013a358c4262ec3bd34aa7085d124
Deleted: sha256:b025f80f98cfb69a52cd92831df7fd664e6800234dbbf23a3f987c099c187c05
Deleted: sha256:a4de85eae15629437f4975d194a6e2beafc75491552aec6ce447381faa77b2fd
Deleted: sha256:40529fb0dad09f427d3bfe1ce6eab16498ad2220bddd43ecc9aafa1982c9ea9c
Deleted: sha256:c4f22e2745a43e3f085510b5badf7c290a0695fc5608cc4e7283b6eb177c493f
Deleted: sha256:27b43d2e6ee5180ecadf4827dce0cddbfd5220a0760e08b2965656253c66c772
Deleted: sha256:0de337169373e6779cb3ca09485e95fedd4ac98abee19b839cd46e294a64f363
Deleted: sha256:73f1cb0f35d3377b825488e38241d0e12c63e7d30946362402dd8ab2e9467d81
Deleted: sha256:5807022bbb80a63e78831d4dff1ac497a450287ce43fbb0381623b19f5d45c8a
Deleted: sha256:1aaef8d601e09d40fc66f3531268e837f4ae3eedf84f94359fa33177f0be4c6e
Deleted: sha256:e0db3ba0aaea8a01d5cb000aeb449c153be0a47a369cafc4e912b85fb18192cf
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.5 d404d78aa797 9 months ago 205MB
删除成功
docker rmi `docker images -q` #删除本地所有镜像, `这个符号是tab键上面的键
docker stats * #查看某个容器所占的资源,*代表容器的名称。
[root@pokes03 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c81ec9d37fe wordpress:latest "docker-entrypoint.s…" 44 minutes ago Up 44 minutes 0.0.0.0:8000->80/tcp root_wordpress_1
1daf35d8d135 mysql:5.7 "docker-entrypoint.s…" 44 minutes ago Up 44 minutes 3306/tcp, 33060/tcp root_db_1
[root@pokes03 ~]# docker stats 1c81ec9d37fe
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1c81ec9d37fe root_wordpress_1 0.01% 64.91MiB / 468.4MiB 13.86% 9.12MB / 8.35MB 0B / 0B 11
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1c81ec9d37fe root_wordpress_1 0.01% 64.91MiB / 468.4MiB 13.86% 9.12MB / 8.35MB 0B / 0B 11
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1c81ec9d37fe root_wordpress_1 0.01% 64.91MiB / 468.4MiB 13.86% 9.12MB / 8.35MB 0B / 0B 11
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1c81ec9d37fe root_wordpress_1 0.01% 64.91MiB / 468.4MiB 13.86% 9.12MB / 8.35MB 0B / 0B 11
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1c81ec9d37fe root_wordpress_1 0.01% 64.91MiB / 468.4MiB 13.86% 9.12MB / 8.35MB 0B / 0B 11
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1c81ec9d37fe root_wordpress_1 0.00% 64.91MiB / 468.4MiB 13.86% 9.12MB / 8.35MB 0B / 0B 11
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1c81ec9d37fe root_wordpress_1 0.00% 64.91MiB / 468.4MiB 13.86% 9.12MB / 8.35MB 0B / 0B 11
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1c81ec9d37fe root_wordpress_1 0.00% 64.91MiB / 468.4MiB 13.86% 9.12MB / 8.35MB 0B / 0B 11
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
1c81ec9d37fe root_wordpress_1 0.00% 64.91MiB / 468.4MiB 13.86% 9.12MB / 8.35MB 0B / 0B 11