操作系统
Linux version 5.15.0-86-generic
(buildd@lcy02-amd64-086)
(gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38)
#96-Ubuntu SMP Wed Sep 20 08:23:49 UTC 2023
查找nginx1.24
sudo docker search nginx:1.24
拉nginx1.24
sudo docker pull nginx:1.24
查看docker镜像,检查是否已经拉取nginx镜像
sudo docker images
创建nginx相关文件夹
mkdir /home/ubuntu/nginx
mkdir /home/ubuntu/nginx/{logs,html,conf}
mkdir /home/ubuntu/nginx/conf/conf.d
创建nginx容器
sudo docker create \
--name testNginx \
-p 80:80 \
7f0fd59e0094
sudo docker create \
--name nginx_test \
-p 80:80 \
-v /home/ubuntu/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /home/ubuntu/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/ubuntu/nginx/logs:/var/log/nginx \
-v /home/ubuntu/nginx/html:/usr/share/nginx/html \
-v /etc/localtime:/etc/localtime:ro \
7f0fd59e0094
创建可后台运行的nginx容器
sudo docker run \
--name nginx_test \
-p 80:80 \
-d 7f0fd59e0094
sudo docker run \
-p 80:80 \
--name nginx_test \
-v /home/ubuntu/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /home/ubuntu/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/ubuntu/nginx/logs:/var/log/nginx \
-v /home/ubuntu/nginx/html:/usr/share/nginx/html \
-v /etc/localtime:/etc/localtime:ro \
-d 7f0fd59e0094
后台运行创建的nginx容器
sudo docker start 容器id &
进入nginx容器
sudo docker exec -it 容器id /bin/bash
复制nginx配置文件
sudo docker cp 容器id:/etc/nginx/nginx.conf /home/ubuntu/nginx
sudo docker cp 容器id:/usr/share/nginx/html /home/ubuntu/nginx/html
sudo docker cp 容器id:/etc/nginx/conf.d /home/ubuntu/nginx/conf/conf.d
修改nginx配置文件用户组、用户权限
sudo chown -R ubuntu:ubuntu /home/ubuntu/nginx
sudo chmod -R 775 /home/ubuntu/nginx
标签:创建,sudo,nginx,conf,ubuntu,home,docker
From: https://www.cnblogs.com/xiaozhe2024/p/18102239