层次:Kernel --> bootfs引导层 --> Base Image -->image -->image (镜像打包好了,只能可读,镜像启动容器后,才可更改)
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vi docker.repo
[docker]
name=docker-ce
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7.9/x86_64/stable/
gpgcheck=0
enabled=1
解释:阿里云centos源可解决docker安装时所需依赖等问题
#根据实际的系统版本下载对应的yum源,这里是centos7版本
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#列出yum源离docker-ce所有的版本
[root@localhost yum.repos.d]# yum list docker-ce --showduplicates
#安装docker
[root@localhost yum.repos.d]# yum install -y docker-ce-19.03.15-3.el7 docker-ce-cli-19.03.15-3.el7
#docker-ce-cli为docker引擎的命令行界面,docker-ce完成所有管理工作
[root@localhost yum.repos.d]# rpm -aq |grep docker
docker-ce-cli-19.03.15-3.el7.x86_64
docker-ce-19.03.15-3.el7.x86_64
#containerd.io为OS API接口的守护进程,将docker鱼OS分离
[root@localhost yum.repos.d]# rpm -qa |grep container
container-selinux-2.119.2-1.911c772.el7_8.noarch
containerd.io-1.6.6-3.1.el7.x86_64
#开启docker并设置开机自启
[root@localhost ~]# systemctl enable --now docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
..........
Live Restore Enabled: false
WARNING: bridge-nf-call-iptables is disabled #docker是走桥接,转发使用的防火墙
WARNING: bridge-nf-call-ip6tables is disabled
#解决两个WARNING
[root@localhost ~]# sysctl -a |grep bridge-nf-call-iptables
net.bridge.bridge-nf-call-iptables = 0
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.docker0.stable_secret"
sysctl: reading key "net.ipv6.conf.ens192.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
#修改系统内核参数
[root@localhost ~]# vi /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
#使修改参数生效
[root@localhost ~]# sysctl --system
* Applying /usr/lib/sysctl.d/00-system.conf ...
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
#在镜像仓库中搜索yakexi007相关镜像
[root@localhost ~]# docker search yakexi007
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
yakexi007/game2048 0
#拉取镜像到本地
[root@localhost ~]# docker pull yakexi007/game2048
Using default tag: latest
latest: Pulling from yakexi007/game2048
534e72e7cedc: Pull complete
f62e2f6dfeef: Pull complete
fe7db6293242: Pull complete
3f120f6a2bf8: Pull complete
4ba4e6930ea5: Pull complete
Digest: sha256:8a34fb9cb168c420604b6e5d32ca6d412cb0d533a826b313b190535c03fe9390
Status: Downloaded newer image for yakexi007/game2048:latest
docker.io/yakexi007/game2048:latest
#查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yakexi007/game2048 latest 19299002fdbe 5 years ago 55.5MB
#查看镜像封装历史记录
[root@localhost ~]# docker history yakexi007/game2048
IMAGE CREATED CREATED BY SIZE COMMENT
19299002fdbe 5 years ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "sed … 0B
5 years ago /bin/sh -c #(nop) EXPOSE 80/tcp 0B
5 years ago /bin/sh -c #(nop) COPY dir:cb74e9c037a3d501c… 600kB
5 years ago /bin/sh -c #(nop) MAINTAINER Golfen Guo 5 years ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
5 years ago /bin/sh -c #(nop) EXPOSE 443/tcp 80/tcp 0B
5 years ago /bin/sh -c #(nop) COPY file:d15ceb73c6ea776c… 1.1kB
5 years ago /bin/sh -c #(nop) COPY file:af94db45bb7e4b8f… 643B
5 years ago /bin/sh -c GPG_KEYS=B0F4253373F8F6F510D42178… 50.1MB
5 years ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.11.7 0B
5 years ago /bin/sh -c #(nop) MAINTAINER NGINX Docker M… 0B
5 years ago /bin/sh -c #(nop) ADD file:7afbc23fda8b0b387… 4.8MB
#创建并运行一个新容器
[root@localhost ~]# docker run -d --name demo -p 80:80 yakexi007/game2048
#查看正在运行的容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b1498afff141 yakexi007/game2048 "/bin/sh -c 'sed -i …" About an hour ago Up About an hour 0.0.0.0:80->80/tcp, 443/tcp demo