docker:
1.安装docker服务,配置镜像加速器
2.下载系统镜像(Ubuntu、 centos)
3.基于下载的镜像创建两个容器 (容器名一个为自己名字全拼,一个为首名字字母)
4.容器的启动、 停止及重启操作
5.怎么查看正在运行的容器和所有容器?
6.怎么退出容器: 两种方法分别实现?
7.怎么连接到运行的容器?
8.查看容器或镜像的内部信息?
9.如何查看所有镜像?
一、安装docker服务,配置镜像加速器
首先安装一台新的虚拟机,这里我装的是最小化版的CentOS7.9。
(1)添加docker-ce 源信息
[root@localhost ~]# wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
(2)修改docker-ce 源
[root@localhost ~]# sed -i 's@download.docker.com@mirrors.tuna.tsinghua.edu.cn/docker-ce@g' /etc/yum.repos.d/docker-ce.repo
(3)更新并安装 Docker-CE
[root@localhost ~]# yum makecache fast
[root@localhost ~]# yum install docker-ce -y #默认安装最新版本
拓展
[root@localhost ~]# yum list docker-ce.x86_64 --showduplicates | sort -r #查看有哪些版本
[root@localhost ~]# yum -y install docker-ce-17.03.2.ce #下载指定版本
配置镜像加速器:
首先你需要有一个阿里云的账号,点击控制台,在产品与服务找到容器镜像服务
找到镜像加速器,选择CentOS开始配置
[root@localhost ~]# mkdir -p /etc/docker
[root@localhost ~]# tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://yiuodseg.mirror.aliyuncs.com"]
> }
> EOF
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
配置清空防火墙规则与启动docker服务
[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld
[root@localhost ~]# /usr/sbin/iptables -F && /usr/sbin/iptables -X && /usr/sbin/iptables -F -t nat && /usr/sbin/iptables -X -t nat
[root@localhost ~]# /usr/sbin/iptables -P FORWARD ACCEPT
[root@localhost ~]# systemctl daemon-reload #重载docker启动配置
[root@localhost ~]# systemctl start docker.service #将docker设为开机自启
[root@localhost ~]# systemctl enable docker.service #启动docker服务
二、下载系统镜像(Ubuntu、 centos)
[root@localhost ~]# docker pull centos:7
[root@localhost ~]# docker pull Ubuntu
三、基于下载的镜像创建两个容器
四、容器的启动、 停止及重启操作
[root@localhost ~]# docker start lzbdm
[root@localhost ~]# docker stop lzbdm
[root@localhost ~]# docker restart lzbdm
五、怎么查看正在运行的容器和所有容器?
[root@localhost ~]# docker ps
[root@localhost ~]# docker ps -a
六、怎么退出容器: 两种方法分别实现?
或者ctrl+p加ctrl+q
七、怎么连接到运行的容器?
#docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
[root@localhost ~]# docker exec -it lzbdm /bin/sh
八、查看容器或镜像的内部信息?
[root@localhost ~]# docker inspect lzbdm
九、如何查看所有镜像?
[root@localhost~]# docker image ls