lidy
的密码
passwd lidy
创建 docker 文件夹,用于存放 docker 相关的数据
cd /home
mkdir docker_data
chmod -R 777 docker_data
visudo
添加以下内容
## Grant administrator privileges
lidy ALL=(ALL) NOPASSWD:ALL
2. 安装 docker 容器
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
docker-ce
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl start docker
# 启动docker服务
systemctl start docker
# 停止docker服务
systemctl stop docker
# 重启docker服务
systemctl restart docker
3. docker中安装 nginx
cd /home/docker_data
mkdir nginx
# 拉取 nginx 镜像
docker pull nginx
# 启动 nginx
docker run --restart=always --name=nginx -p 80:80 -d nginx
docker cp nginx:/etc/nginx /home/docker_data/nginx/conf
docker cp nginx:/usr/share/nginx/html /home/docker_data/nginx/html
docker cp nginx:/var/log/nginx /home/docker_data/nginx/logs
# 停止 docker 容器
docker stop nginx
# 删除 docker 容器
docker rm -f nginx
docker run --restart=always --name=nginx -p 80:80 \
-v /home/docker_data/nginx/conf:/etc/nginx \
-v /home/docker_data/nginx/html:/usr/share/nginx/html \
-v /home/docker_data/nginx/logs:/var/log/nginx \
-d nginx