Mount Nginx Container in Docker: Guide
To mount a directory to an Nginx container, you can use the -v parameter in the docker run command.
For example, to mount the local directory /path/to/local to the /usr/share/nginx/html directory in the nginx container, you can use the following command:
docker run -d -p 80:80 -v /path/to/local:/usr/share/nginx/html nginx
Among them:
- The ‘-d’ parameter indicates running the container in the background.
- Mapping the local port 80 to the container’s port 80 is represented by -p 80:80.
- “-v /path/to/local:/usr/share/nginx/html” means to mount the local directory “/path/to/local” to the container’s “/usr/share/nginx/html” directory.
Therefore, once the nginx container is started, accessing files in the local directory /path/to/local is equivalent to accessing files in the directory /usr/share/nginx/html within the container.