Search code examples
dockerapachedocker-compose

docker compose I want use my local directory C:/html for /var/www/html


Hello I want to publish the "index.php" from the local folder "C:\html\index.php" with docker-compose.yml

in localhost I get the typical apache html "It works". But I do not get the content of my local folder. What I am doing wrong?

here is my docker-compose file:

version: "3"
 
services:
 
  # --- MySQL 5.7
  #
  mysql:
    container_name: "dstack-mysql"
    image: bitnami/mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=admin
      - MYSQL_PASSWORD=root
    ports:
      - '3306:3306'
  php:
    container_name: "dstack-php"
    image: bitnami/php-fpm:8.1
  

 
 
  # --- Apache 2.4
  #
  apache:
    container_name: "dstack-apache"
    image: bitnami/apache:2.4
    ports:
      - '80:8080'
      - '443:8443'
    depends_on:
      - php
   
  volumes:
    - C:/html:/var/www/html
  phpmyadmin:
    container_name: "dstack-phpmyadmin"
    image: bitnami/phpmyadmin:latest
    depends_on:
      - mysql
    ports:
      - '81:8080'
      - '8143:8443'
    environment:
      - DATABASE_HOST=host.docker.internal
volumes:
  dstack-mysql:
    driver: local

Update:

volumes: - ./html:/var/www/html

Doesn't works.

I want to have a web development docker environment where I edit in the folder C:\html\index_hello.html in my computer and I will see the changes in the browser localhost:8080, the changes I did. My expectation is that I write in the browser http://localhost:8080/index_hello.html. Did I something wrong? shall I edit other files e.g. apache.conf?


Solution

  • I would suggest avoiding hardcoding directories and using relative directories.

    If you place your docker-compose into your C:/html folder and then change your volume to read:

    volumes:
        - .:/var/www/html
    

    if you run the following:

    cd C:/html
    docker-compose up -d
    

    you are telling docker-compose to use . meaning the current directory.

    if you put the docker-compose.yml in the C:/ directory you can run change the volume to:

    volumes:
        - ./html:/var/www/html
    

    then the docker compose command should remain the same.