0

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?

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

Hi, thanks for your ideas. Well, generally I only want php-httpd to see my sources (the database and phpmyadmin do not need them at this stage), so I think that should be ok. For the second part and the "DocumentRoot": Yes, I understood this. The thing is that when I use "DocumentRoot" the directory gets created (so I am obviously at the right directory), but when I use my "src" folder, its contents are not visible inside docker. If docker users the src folder, I'd expect to see my sources in the container.
You are welcome : )I tested your docker file yesterday and I didn't notice the behavior that you describe. The mount works as expected.
0

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.