Example docker-compose.yml content:
Note: the current directory /root/docker/nginx
version: "3"
services:
nginx:
image: nginx:latest
container_name: nginx
restart: always
ports:
- "80:80"
volumes:
- ./conf.d:/etc/nginx/conf.d
- ./log:/var/log/nginx
- ./www:/usr/share/nginx/html
When we want to use a certain directory, but don’t want to copy it directly, because it will take up space, subsequent source directory file changes need to be processed.
In order to solve the above problems, we thought of using soft links.
Then we created a soft connection on the host through ln -s, such as ln -s /root/upload ./www/upload
However, the resource where the soft link was created cannot be accessed at all.
Obviously the resource does not exist, so we should enter the container to see if the resource that establishes the soft connection exists.
Enter the container through docker exec -it nginx bash, and find that the soft link exists, but the source directory file does not.
At this point, we should mount the data volume to solve this problem.
Modify the docker-compose.yml file:
version: "3"
services:
nginx:
image: nginx:latest
container_name: nginx
restart: always
ports:
- "80:80"
volumes:
- ./conf.d:/etc/nginx/conf.d
- ./log:/var/log/nginx
- ./www:/usr/share/nginx/html
- /upload:/root/docker/nginx/www
The above modification is mainly to mount the host /upload directory to the container /root/docker/nginx/www directory .
Then execute the following command:
docker-compose down
docker-compose up -d
Finally, visit http://ip:80/xxx, the display is normal.
reference:
In the Docker container, use nginx proxy PHP to access the soft link and report 404
Why is the soft link in linux inaccessible in docker? - SegmentFault 思否