安装Docker
1.防火墙
2.yum源
3.安装基础软件
更新yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all #清除yum源缓存
yum makecache #生成新缓存
iptables -F #清空规则
getenforce #disabled
yum install -y bash-completion vim lrzsz wget expect net-tools nc nmap tre dosZunix htop iftopiotop unzip telnet sl psmisc nethogs glances bc ntpdate openldap-devel
systemctl disable firewalld
systemctl stop firewalld
history #查看前面执行过的命令
uname -r
安装Docker
开启linux 内核的流量转发
cat < /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.ip_forward = 1
EOF
#加载修改内核的参数,配置文件
modprobe br_netfilter
sysctl -p /etc/sysctl.d/docker.conf
报错了
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directory
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory
net.ipv4.conf.default.rp_filter = 0
net.ipv4.ip_forward = 1
报错解决方法
modprobe br_netfilter
sysctl -p /etc/sysctl.d/docker.conf
使用yum 安装docker
查看yum 源里有没有 docker-ce 文件包
yum list docker-ce --showduplicates | sort -r
Error: No matching Packages to list
- updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
- extras: mirrors.aliyun.com
- base: mirrors.aliyun.com
curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
更新YUM缓存
yum clean all && yum makecache
#可以直接yum安装docker了
#yum 安装
yum install docker-ce-20.10.6 -y
#查看源中可用版本
yum list docker-ce --showduplicates | sort -r
#如果要删除docker
yum remove -y docker-ce-20.10.6 # 版本号
#启动,使用docker
#配置docker加速器
mkdir -p /etc/docker
touch /etc/docker/daemon.json
vim /etc/docker/daemon.json
{
"registry-mirrors":[
"https://8xpk5wnt.mirror.aliyuncs.com"
]
}
#启动docker
systemctl daemon-reload
systemctl enable docker
#启动
systemctl restart docker
#验证是否启动成功
ps -ef | grep docker
docker ps #查看容器
docker images #查看镜像
[root@VM-4-11-centos etc]# docker version
Client: Docker Engine - Community
Version: 20.10.18
API version: 1.41
Go version: go1.18.6
Git commit: b40c2f6
Built: Thu Sep 8 23:14:08 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.6
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 8728dd2
Built: Fri Apr 9 22:43:57 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
--------------------------
Nginx web 服务,运行一个80端口的网站
如果让你用docker运行nginx 该怎么玩
1.获取镜像,获取是从你配置好的docker镜像站中去拉nginx镜像
#先搜索一下,镜像文件是否在
docker search nginx
#查看镜像
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 9 months ago 141MB
#删除镜像
docker rmi 605c77e624dd #IMAGE ID的值
#拉取镜像
docker pull nginx
docker pull redis
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete
a9edb18cadd1: Pull complete
589b7251471a: Pull complete
186b1aaa4aa6: Pull complete
b4df32aa5a72: Pull complete
a0bcbecc962e: Pull complete
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
#再次查镜像
docker image ls
#运行nginx镜像
docker run 参数 镜像名字或ID
#-d 后台运行容器
#-p 80:80 端口映射, 宿主机端口:容器内端口,你访问宿主机的这端口也就访问到了容器内的端口
docker run -d -p 80:80 nginx
#docker run 命令会返回一个容器ID
#查看容器是否在运行
docker ps
#这时就可以访问测试一下
#此时可以访问宿主机的80端口,查到容器的80端口的应用是什么了
IP:80 #IP+端口在Google Chrome的地址栏里访问
#可以尝试停止容器
docker stop 容器ID
docker stop 1a033aef64fe
#启动容器
docker stater 窗口ID
docker start 1a033aef64fe