[root@localhost ~]# yum list docker-ce --showduplicates | sort -r #列出docker可用的版本
[root@localhost ~]# docker pull ubuntu:16.04 #获取镜像
16.04: Pulling from library/ubuntu
35b42117c431: Pull complete
ad9c569a8d98: Pull complete
293b44f45162: Pull complete
0c175077525d: Pull complete
Digest: sha256:a4d8e674ee993e5ec88823391de828a5e9286a1597b731eaecaaf9066cfdf539
Status: Downloaded newer image for ubuntu:16.04
[root@localhost ~]# docker run -it --rm \
> ubuntu:16.04 \
> /bin/bash #以镜像为基础启动一个容器
root@7f53b43c9ffa:/# cat /etc/os-release #进入容器,查看当前系统版本
[root@localhost ~]# docker images ls #列出镜像
[root@localhost ~]# docker system df #查看镜像、容器、数据卷所占用的空间
[root@localhost ~]# docker run -t -i ubuntu:16.04 /bin/bash #启动一个docker终端,允许用户交互
-t : 选项让Dokcer分配一个伪终端(pseudo-tty)并绑定到容器的标准输入上
-i : 让容器的标准输入保持打开
[root@localhost ~]# docker run -d ubuntu:16.04 /bin/sh -c "while true; do echo hello world; sleep 1; done" #后台运行
WARNING: IPv4 forwarding is disabled. Networking will not work.
b06574a649ef425081181e52419373da2af28d3dbff89e3618bde472378b25dd
[root@localhost ~]# docker container ls #查看容器信息
[root@localhost ~]# docker container logs b06574a649ef #查看后台运行日志
[root@localhost ~]# docker container ls -a #查看终止状态的容器
[root@localhost ~]# docker container prune #如果数量太多要一个个删除会很麻烦,清理掉所有终止所有处于终止状态的容器
[root@localhost ~]# docker ps -aq
[root@localhost ~]# docker exec -it 961 bash #进入容器
[root@localhost ~]# docker image ls #查看本地镜像
[root@localhost ~]# docker image rm f68 #删除本地镜像
[root@localhost ~]# docker image ls #查看本地镜像
迁移镜像:
[root@localhost mynginx]# docker image ls nginx #查看本地镜像
[root@localhost mynginx]# docker image ls nginx:v3
[root@localhost mynginx]# docker save nginx:v3 | gzip > nginx:v3.tar.gz #保存镜像
然后将保存的nginx:v3镜像文件复制到另一个机器上面
[root@localhost ~]# scp -r root@192.168.56.42:/root/mynginx/nginx\:v3.tar.gz /mnt/ #本机地址56.43,从远处(56.42)复制到本地
[root@localhost mnt]# docker load -i nginx\:v3.tar.gz #加载镜像
[root@localhost ~]# docker search centos #搜索官方镜像