Hey everyone! I'm working on creating a Docker container using a Dockerfile, and I've hit a bit of a snag. I'm setting up an NGINX web server, and while the container starts up fine, I'm having issues with mounting the HTML folder from my host. When I mount it, the HTML folder ends up empty because my host folder is empty too. Here's a snippet of my docker-compose.yaml:
```yaml
nginx:
build: .
ports:
- "8081:80"
volumes:
- c:\docker: /usr/share/nginx/html
```
And part of my Dockerfile looks like this:
```dockerfile
VOLUME /usr/share/nginx/html
ENTRYPOINT ["nginx", "-g", "daemon off;"]
```
So my question is: is there a way to mount the folder from the container to the host without it getting overwritten? I want to be able to write (or overwrite) files in that folder too, so I'm assuming read-only isn't the way to go. What's the best approach here?
3 Answers
When you mount a host folder to a container, the files from the container won't appear on the host if they existed before the mount. You won't be able to overwrite the host folder content from the container once the mount is in place. If you want files from the container inside your host, you need to place them in the host's directory beforehand or create a process to copy them over after the container starts.
It sounds like your understanding of bind mounts might need a little tweaking. From what you described, it seems you're trying to edit the files in the container but expecting them to show up on your host. That's not how it works—what's in the host's directory before the mount will always take precedence after the mount. If you want to add new files or edit existing ones, you might consider using a script that syncs those changes to your host.
If you want to have the HTML files available to edit on your host and also allow your application to write to them, you might want to think about a different workflow. You could have a directory on your host where you manually place files or have your application place files after generating them. This way, you ensure that the host and container can communicate correctly.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String