I need to include some PHP code in the docker image and at the same time use some code from host directory while maintaining a certain file structure inside the running container.

How to write mount of hostdir1 in docker-compose.yml file correctly?

Let me explain with a short example:

  1. inside image (after build):
tree /mount mount/ ├── 1.txt ├── 4.txt └── 5.txt 
 cat mount/1.txt internal 
  1. on the host filesystem:
hostdir1/ ├── 1.txt ├── 2.txt └── somedir └── 3.txt 
 cat hostdir1/1.txt external 
  1. I need to mount host folder to contaider using smth like overlayFS and get the following file structure in the running container:
mount/ ├── 1.txt ├── 2.txt ├── 4.txt ├── 5.txt └── somedir └── 3.txt 
cat mount/1.txt internal 

Upd: Here They simply mount the directory into the container, overwriting all the contents of the directory in the image. I need to mount the host directory from below to the desired image directory. Keeping available all the files that are in the image and adding to them those files and directories that are on the server but are not in the image.

3

Related questions 2449 How to copy files from host to Docker container? 2809 Copying files from Docker container to host 901 How to mount a host directory in a Docker container Related questions 2449 How to copy files from host to Docker container? 2809 Copying files from Docker container to host 901 How to mount a host directory in a Docker container 4425 How is Docker different from a virtual machine? 1075 Exploring Docker container's file system 851 How to include files outside of Docker's build context? 595 How to rebuild docker container in docker-compose.yml? 618 Docker Compose wait for container X before starting Y 371 Mount current directory as a volume in Docker on Windows 10 486 Root password inside a Docker container Load 7 more related questions Show fewer related questions

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.