[root@localhost ~]# docker version Client: Version: 18.09.0 API version: 1.39 Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:48:22 2018 OS/Arch: linux/amd64 Experimental: false
Server: Docker Engine - Community Engine: Version: 18.09.0 API version: 1.39 (minimum version 1.12) Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:19:08 2018 OS/Arch: linux/amd64 Experimental: false
还有一种方法:
1
curl -fsSL https://get.docker.com/ | sh
将Docker服务设为开机启动:systemctl enable docker
基本操作命令
操作
命令
说明
检索
docker search 关键字
在docker hub上检索镜像的详情信息
拉取
docker pull 镜像名:tag
:tag:软件版本,默认是latest
镜像列表
docker images
查看本地所有镜像详情
镜像删除
docker rmi image-id
删除指定的本地镜像
容器删除
docker rm base
删除base容器,如果base正在运行,则可以使用-f进行强制删除
显示容器
docker ps -a
显示当前宿主机所有容器;没有-a表示显示当前宿主机正在运行的容器
运行容器
docker run -d -p 宿主机端口:容器端口 -name 容器名 镜像名
-d 表示以后台方式运行 -p代表映射端口 -name代表容器名
以交互式命令进入容器
docker exec -it 容器名 /bin/bash
以交互式命令进入容器,可以执行/bin/bash命令
停止容器
docker stop 容器名/容器ID
选定容器停止
启动容器
docker start 容器名/容器ID
选定容器启动
容器日志
docker logs 容器名/容器ID
容器的日志查看
防火墙
service firewalld status
查看防火墙状态
防火墙
service firewalld stop
关闭防火墙
强制关闭docker
killall Dokcer
关闭Dokcer
实际操作记录(展示部分)
查看镜像列表
1 2 3 4 5 6 7 8
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry.docker-cn.com/library/mongo latest 10dce532716f 2 months ago 393MB redis latest ce25c7293564 2 months ago 95MB mysql latest f991c20cb508 3 months ago 486MB registry.docker-cn.com/library/rabbitmq 3-management d69a5113ceae 4 months ago 149MB registry.docker-cn.com/library/zookeeper latest f336949ce7a1 4 months ago 148MB registry.docker-cn.com/library/elasticsearch latest 5acf0e8da90b 5 months ago 486MB
显示容器
1 2 3 4 5 6 7 8
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d1cb816cdc88 10dce532716f "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myMongo f88e287867ce f336949ce7a1 "/docker-entrypoint.…" 2 months ago Exited (143) 7 minutes ago myZooKeeper 58cfffc74b1b 5acf0e8da90b "/docker-entrypoint.…" 2 months ago Exited (143) 2 months ago myES 57d2aa554d9e d69a5113ceae "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRabbitMQ fd0392de1d53 redis:latest "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRedis 5757e7f9c83d mysql:latest "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago mysql01
启动容器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d1cb816cdc88 10dce532716f "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myMongo f88e287867ce f336949ce7a1 "/docker-entrypoint.…" 2 months ago Exited (143) 7 minutes ago myZooKeeper 58cfffc74b1b 5acf0e8da90b "/docker-entrypoint.…" 2 months ago Exited (143) 2 months ago myES 57d2aa554d9e d69a5113ceae "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRabbitMQ fd0392de1d53 redis:latest "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRedis 5757e7f9c83d mysql:latest "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago mysql01 [root@localhost ~]# docker start 5757e7f9c83d 5757e7f9c83d [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d1cb816cdc88 10dce532716f "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myMongo f88e287867ce f336949ce7a1 "/docker-entrypoint.…" 2 months ago Exited (143) 9 minutes ago myZooKeeper 58cfffc74b1b 5acf0e8da90b "/docker-entrypoint.…" 2 months ago Exited (143) 2 months ago myES 57d2aa554d9e d69a5113ceae "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRabbitMQ fd0392de1d53 redis:latest "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRedis 5757e7f9c83d mysql:latest "docker-entrypoint.s…" 2 months ago Up 4 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql01
停止容器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d1cb816cdc88 10dce532716f "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myMongo f88e287867ce f336949ce7a1 "/docker-entrypoint.…" 2 months ago Exited (143) 10 minutes ago myZooKeeper 58cfffc74b1b 5acf0e8da90b "/docker-entrypoint.…" 2 months ago Exited (143) 2 months ago myES 57d2aa554d9e d69a5113ceae "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRabbitMQ fd0392de1d53 redis:latest "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRedis 5757e7f9c83d mysql:latest "docker-entrypoint.s…" 2 months ago Up About a minute 0.0.0.0:3306->3306/tcp, 33060/tcp mysql01 [root@localhost ~]# docker stop 5757e7f9c83d 5757e7f9c83d [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d1cb816cdc88 10dce532716f "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myMongo f88e287867ce f336949ce7a1 "/docker-entrypoint.…" 2 months ago Exited (143) 11 minutes ago myZooKeeper 58cfffc74b1b 5acf0e8da90b "/docker-entrypoint.…" 2 months ago Exited (143) 2 months ago myES 57d2aa554d9e d69a5113ceae "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRabbitMQ fd0392de1d53 redis:latest "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRedis 5757e7f9c83d mysql:latest "docker-entrypoint.s…" 2 months ago Exited (0) 2 seconds ago mysql01
以交互式命令进入容器
1 2 3 4 5 6 7 8 9 10 11
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d1cb816cdc88 10dce532716f "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myMongo f88e287867ce f336949ce7a1 "/docker-entrypoint.…" 2 months ago Exited (143) 13 minutes ago myZooKeeper 58cfffc74b1b 5acf0e8da90b "/docker-entrypoint.…" 2 months ago Exited (143) 2 months ago myES 57d2aa554d9e d69a5113ceae "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRabbitMQ fd0392de1d53 redis:latest "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago myRedis 5757e7f9c83d mysql:latest "docker-entrypoint.s…" 2 months ago Up 5 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql01 [root@localhost ~]# docker exec -it 5757e7f9c83d /bin/bash root@5757e7f9c83d:/# ls bin boot dev docker-entrypoint-initdb.d entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var