1.安装docker服务,配置镜像加速器
1.1 使用yum进行安装
添加docker-ce的源信息
[root@localhost ~]# yum install yum-utils device-mapper-persistent-data lvm2 -y
[root@localhost ~]# yum-config-manager --add-repo
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
修改ce源的信息
[root@localhost ~]# sed -i
's@download.docker.com@mirrors.tuna.tsinghua.edu.cn/docker-ce@g'
/etc/yum.repos.d/docker-ce.repo
更新源
[root@localhost ~]# yum makecache fast
安装docker-ce
yum -y install docker-ce
配置镜像加速器(使用的是阿里云)
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://u37h0ohm.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
docker info 查看弹出一下内容表示成功
2.下载系统镜像(Ubuntu、 centos)
[root@localhost docker]# sudo docker pull ubuntu
[root@localhost docker]# sudo docker pull centos
3.基于下载的镜像创建两个容器 (容器名一个为自己名字全拼,一个为首名字字母)
[root@localhost docker]#docker run -it --name zZ ubuntu /bin/bash
[root@localhost docker]#docker run -it --name zz centos /bin/bash
4.容器的启动、 停止及重启操作
[root@localhost docker]# docker start zz
zz
[root@localhost docker]# docker stop zzzz[root@localhost docker]# docker restart zz
zz
5.怎么查看正在运行的容器和所有容器?
docker ps
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6138358cdfc0 ubuntu "/bin/bash" About a minute ago Up 35 seconds zZ
0ed8dbde6c22 centos "/bin/bash" 6 minutes ago Up 3 seconds zz
6.怎么退出容器: 两种方法分别实现?
[root@0ed8dbde6c22 /]# exit
exit
[root@localhost ~]#
或者ctrl+p+q(退出)
7.怎么连接到运行的容器?
[root@localhost ~]# docker exec -it zz /bin/bash
[root@0ed8dbde6c22 /]#
8.查看容器或镜像的内部信息?
docker inspect zz
[{"Id": "0ed8dbde6c22181b9822d4196732561b5ef0d3bfdf3970876520ecf1cfa5119c","Created": "2023-08-24T05:44:56.870712427Z","Path": "/bin/bash","Args": [],"State": {"Status": "running","Running": true,"Paused": false,"Restarting": false,
9.如何查看所有镜像?
docker images
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 01f29b872827 2 weeks ago 77.8MB
mysql 5.7 2be84dd575ee 2 months ago 569MB
centos latest 5d0da3dc9764 23 months ago 231MB