2. Create nginx configuration file
3. Create nginx container and run it
4. Configure nginx static resources
1. Download the image
Dockerhub official website: Docker
docker pull nginx
docker pull nginx downloads the latest version and defaults to latest
Download the specified version docker pull nginx:xxx
2. Create nginx configuration file
You need to create an nginx configuration file before starting the container, because the nginx container only has the /etc/nginx directory and no nginx.conf file. If neither the server nor the container has an nginx.conf file, executing the startup command docke will create nginx.conf as a directory. This Not the result we want
#创建挂载目录
mkdir -p /usr/local/nginx/conf
mkdir -p /usr/local/nginx/log
mkdir -p /usr/local/nginx/html
Copy the nginx.conf file and conf.d folder in the container to the host
# 生成容器
docker run --name nginx -p 9001:80 -d nginx
# 将容器nginx.conf文件复制到宿主机
docker cp nginx:/etc/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf
# 将容器conf.d文件夹下内容复制到宿主机
docker cp nginx:/etc/nginx/conf.d /usr/local/nginx/conf/conf.d
# 将容器中的html文件夹复制到宿主机
docker cp nginx:/usr/share/nginx/html /usr/local/nginx/
Delete the container after copying is complete
docker stop nginx
docker rm nginx
3. Create nginx container and run it
docker run \
-p 9002:80 \
--name nginx \
-v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/local/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /usr/local/nginx/log:/var/log/nginx \
-v /usr/local/nginx/html:/usr/share/nginx/html \
-v /root/data/mp4/:/data/mp4 \
-d nginx:latest
Here I will mount /root/data/mp4/ with the container’s /data/mp4. The /data/mp4 folder will be automatically created.
4. Configure nginx static resources
Upload a video file to the /root/data/mp4/ directory
There will also be corresponding files in the container.
Use docker exec -it nginx /bin/bash container to view inside
Configure the path in /home/nginx/conf/conf.d
Finally restart the nginx container
docker restart nginx
Access video via URL