简体   繁体   中英

files not visible in docker-compose

I am quite new to docker and I try to build a LAMP stack with docker-compose. I have found a nice tutorial over there . I think I understood the difference between volumes and bind mounts, however, I guess I am running into a problem at some point. I want to make one of my folders available to the LAMP stack (my sources, residing in a folder 'src'). However, the sources are not visible within the /var/www/html folder.

My docker-compose file looks like this:

version: "3.7"

services: 
  mariadb: 
    environment: 
      MYSQL_ALLOW_EMPTY_PASSWORD: "no"
      MYSQL_DATABASE: testdb
      MYSQL_PASSWORD: testpassword
      MYSQL_ROOT_PASSWORD: rootpwd
      MYSQL_USER: testuser
      TZ: Europe/Rome
    image: "mariadb:10.5.2"
    volumes: 
      - "mariadb-volume:/var/lib/mysql"
      
  php-httpd: 
    image: "php:7.3-apache"
    ports: 
      - "80:80"
    volumes: 
       - ./src/:/var/www/html/
       
  phpmyadmin: 
    image: phpmyadmin/phpmyadmin
    links: 
      - "mariadb:db"
    ports: 
      - "8081:80"

volumes: 
  mariadb-volume: ~

Phpmyadmin works just fine, also the docker-compose runs without any warnings. My compose command is

docker-compose up -d --force-recreate

Interestingly, when I change "./src/" for "./DocumentRoot", the folder DocumentRoot is created on my host machine. However, placing files in DocumentRoot on the host or in /var/www/html in docker does not show the files on the docker or host, respectively. Nevertheless, I can say for sure that I am in the right directory at least.

Is there some trick or parameter I need to pass along to let docker see the files on my host?

I want to make one of my folders available to the LAMP stack (my sources, residing in a folder 'src'). However, the sources are not visible within the /var/www/html folder.

I think that there is a confusion about how mounts work with docker.
When you specify a mount for a docker container such as :

 php-httpd: 
    image: "php:7.3-apache"
    ports: 
      - "80:80"
    volumes: 
       - ./src/:/var/www/html/

Only the container php-httpd will be set with the mount, not the other containers of your LAMP stack.
If you need to set that mount on other containers, do it explicitly on them.

Interestingly, when I change "./src/" for "./DocumentRoot", the folder DocumentRoot is created on my host machine. However, placing files in DocumentRoot on the host or in /var/www/html in docker does not show the files on the docker or host, respectively.

That is the way which works the mounts. When the folder exists on the host (here src ) , docker uses it to mount its content from host to container. When the folder doesn't exit on the host, Docker creates it.

I have finally found a solution. I am splitting the docker-compose file and I do the php-httpd part in a separate dockerfile. There, I can copy my sources into the dockercontainer.

It is not the original solution, so I would still be grateful for input on the problem why the bind mount does not work, but this solution works for me.

Hah... thanks again. Your question has triggered another thought. It's quite natural to me, so I didn't mention it: When I execute the docker-compose from Desktop, everything works fine. However, if I execute it from my usual working directory, it does not. My usual working directory is a mounted volume with VeryCrypt on Windows. Obviously there are issues sharing the directory in the latter case.

Just in case anybody is experiencing that error too in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM