目录
一、安装docker服务
二、配置镜像加速器
三、下载系统镜像(Ubuntu、 centos )
四、基于下载的镜像创建两个容器(容器名一个为自己名字全拼,一个为首名字字母 )
五、容器的启动、 停止及重启操作
六、查看正在运行的容器和所有容器
七、退出容器: 两种方法分别实现
八、连接到运行的容器
九、查看容器或镜像的内部信息
十、查看所有镜像
一、安装docker服务
安装软件包
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
设置yum源
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
查看版本信息并安装docker-ce
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
[root@localhost ~]# yum -y install docker-ce-18.03.1.ce
启动docker设置开机自启
[root@localhost ~]# systemctl enable --now docker
二、配置镜像加速器
[root@localhost ~]# mkdir -p /etc/docker
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://5twf62k1.mirror.aliyuncs.com"]
}
重启容器docker (重启 Docker 进程加速器即可生效)
[root@localhost ~]# systemctl restart docker
验证拉取镜像速度
[root@localhost ~]# docker pull mysql
三、下载系统镜像(Ubuntu、 centos )
[root@localhost ~]# docker pull ubuntu
[root@localhost ~]# docker pull centos
查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 3218b38490ce 20 months ago 516MB
ubuntu latest ba6acccedd29 22 months ago 72.8MB
centos latest 5d0da3dc9764 23 months ago 231MB
四、基于下载的镜像创建两个容器(容器名一个为自己名字全拼,一个为首名字字母 )
[root@localhost ~]# docker run --name shenqilun -it ubuntu /bin/bash
root@2b772b9b44ed:/# exit
exit
[root@localhost ~]# docker run --name SQL -it centos /bin/bash
[root@f76eb823b8b3 /]# exit
exit
查看容器
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f76eb823b8b3 centos "/bin/bash" 46 seconds ago Exited (0) 40 seconds ago SQL
2b772b9b44ed ubuntu "/bin/bash" About a minute ago Exited (127) About a minute ago shenqilun
五、容器的启动、 停止及重启操作
使用start、stop、restart命令
以shenqilun容器为例
启动
[root@localhost ~]# docker start shenqilun
shenqilun
停止
[root@localhost ~]# docker stop shenqilun
shenqilun
重启
[root@localhost ~]# docker restart shenqilun
shenqilun
六、查看正在运行的容器和所有容器
正在运行的容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2b772b9b44ed ubuntu "/bin/bash" 4 minutes ago Up About a minute shenqilun
所有容器
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f76eb823b8b3 centos "/bin/bash" 3 minutes ago Exited (0) 3 minutes ago SQL
2b772b9b44ed ubuntu "/bin/bash" 4 minutes ago Up About a minute shenqilun
七、退出容器: 两种方法分别实现
1、exit
2、crtl + p +Q
八、连接到运行的容器
[root@localhost ~]# docker exec -it shenqilun /bin/bash
root@2b772b9b44ed:/#
九、查看容器或镜像的内部信息
[root@localhost ~]# docker inspect shenqilun | 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",
十、查看所有镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 3218b38490ce 20 months ago 516MB
ubuntu latest ba6acccedd29 22 months ago 72.8MB
centos latest 5d0da3dc9764 23 months ago 231MB