1.安装docker服务,配置镜像加速器
安装软件包
[root@bogon ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
设置yum源
[root@bogon ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装
[root@bogon ~]# yum list docker-ce --showduplicates | sort -r
[root@bogon ~]# yum -y install docker-ce-18.03.1.ce
启动docker设置开机自启
[root@bogon ~]# systemctl enable --now docker
配置镜像加速器
[root@bogon ~]# mkdir -p /etc/docker
[root@bogon ~]# tee /etc/docker/daemon.josn <<- 'EOF'
> {
> "registry-mirrors": ["https://09s7n5di.mirror.aliyuncs.com" ]
> }
> EOF
2.下载系统镜像(Ubuntu、 centos)
[root@bogon ~]# docker pull ubuntu
[root@bogon ~]# docker pull centos
[root@bogon ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest ba6acccedd29 22 months ago 72.8MB
centos latest 5d0da3dc9764 23 months ago 231MB
3.基于下载的镜像创建两个容器 (容器名一个为自己名字全拼,一个为首名字字母)
[root@bogon ~]# docker run --name longsiqi -it ubuntu /bin/bash
root@dca8744849ff:/# exit
exit
[root@bogon ~]# docker run --name LSQ -it centos /bin/bash
[root@05ca7fc065c9 /]# exit
exit
[root@bogon ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
05ca7fc065c9 centos "/bin/bash" 18 seconds ago Exited (0) 9 seconds ago LSQ
dca8744849ff ubuntu "/bin/bash" 3 minutes ago Exited (0) 2 minutes ago longsiqi
4.容器的启动、 停止及重启操作
[root@bogon ~]# docker start LSQ
LSQ
[root@bogon ~]# docker stop LSQ
LSQ
[root@bogon ~]# docker restart LSQ
LSQ
5.怎么查看正在运行的容器和所有容器?
[root@bogon ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
05ca7fc065c9 centos "/bin/bash" 5 minutes ago Up About a minute LSQ
[root@bogon ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
05ca7fc065c9 centos "/bin/bash" 6 minutes ago Up About a minute LSQ
dca8744849ff ubuntu "/bin/bash" 9 minutes ago Exited (0) 8 minutes ago longsiqi
b76ab0ae0e34 nginx "/docker-entrypoint.…" 26 minutes ago Exited (0) 23 minutes ago sad_goldwasser
6.怎么退出容器: 两种方法分别实现?
exit ctrl+p+Q
7.怎么连接到运行的容器?
[root@bogon ~]# docker exec -it LSQ /bin/bash
[root@05ca7fc065c9 /]#
8.查看容器或镜像的内部信息?
[root@bogon ~]# docker inspect LSQ | grep -i address
"LinkLocalIPv6Address": "",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"IPAddress": "172.17.0.2",
"MacAddress": "02:42:ac:11:00:02",
"IPAddress": "172.17.0.2",
"GlobalIPv6Address": "",
"MacAddress": "02:42:ac:11:00:02",
9.如何查看所有镜像?
[root@bogon ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest eea7b3dcba7e 6 days ago 187MB
ubuntu latest ba6acccedd29 22 months ago 72.8MB
centos latest 5d0da3dc9764 23 months ago 231MB