Ok, so I need to directly edit files inside a Docker container. Why? Well, that’s not really important right now, let’s just say that I need to.
Docker containers are run inside Docker’s own VM, at least on a Mac… so you don’t really have direct access to that file system.
There are some weird work-arounds using terminals, but you still end up without ‘native’ access to the files. I want native access to the files.
So, the only seemingly proper way to do what I want, is with a bind mount. That means mounting a folder on my local machine inside a Docker container.
If you edit the file, either inside the container, or inside the local file system, the bind-mount is reading and writing to the same file.
See bind-mounts here:
So, let’s give this a whirl…
I’m using Docker Compose, if you don’t know what that is already… it’s just a .yaml file with instructions for Docker to bring up a, or multiple, containers.
services: wordpress: image: iwbp/iwbwpwebsitefactory:latest restart: always --- volumes: #- wordpress:/var/www/html #Bind Mount - /local/filesystem/path:/var/www/html
That’s not a complete Docker Compose file, just the parts of interest here.
Notice the ‘volumes:’ section, it’s specifically related to the ‘wordpress’ service.
In this example, the directory /local/filesystem/path will be mounted inside the Docker container… as /var/www/html.