I'm new with docker and docker-compose, and I have issue with persistent storage. I have three folders that I need to keep files outside of docker. I don't know what I'm doing wrong.
docker-compose.yaml
version: '3.3'
services:
webserver:
build:
context: ./
dockerfile: webserver.DockerFile
ports:
- 80:80
- 443:443
volumes:
- html:/var/www/html
- platforms:/var/www/platforms
- sites-available:/etc/apache2/sites-available
mysql-server:
image: mysql:8.0.20
restart: always
environment:
MYSQL_ROOT_PASSWORD: somepassword555
phpmyadmin:
image: phpmyadmin/phpmyadmin:5.0.1
restart: always
environment:
PMA_HOST: mysql-server
PMA_USER: root
PMA_PASSWORD: somepassword555
ports:
- "8080:80"
When I run build on this, I get empty folders in webserver. Folders on host are not empty.
EDIT: to clarify
on HOST there are:
webserver.DockerFile
docker-compose.yml
- html
--- index.php
--- ...
- platforms
--- dir1
--- dir2
--- dir3
--- ...
- sites-available
--- backend.conf
--- frontend.conf
inside webserver.Dockerfile there are:
RUN mkdir -p /var/www/html/backend
RUN mkdir -p /var/www/html/frontend
RUN a2ensite backend.conf frontend.conf
which does not create 'backend' and 'frontend' directories on HOST, and then fails on a2ensite, with error:
ERROR: Site backend does not exist!
ERROR: Site frontend does not exist!
ERROR: Service 'webserver' failed to build: The command '/bin/sh -c a2ensite backend.conf frontend.conf' returned a non-zero code: 1
That all indicated to me that the directories on the DOCKER that I wanted to be linked/mounted with HOST are in fact empty:
/var/www/html
/var/www/platforms
/etc/apache2/sites-available
but the directories on HOST are not empty.
Remember the folder to the left of the double dots is bound into the container :/var/www/html . So if the container is not checked on startup if the folder is full it will be overwritten and is empty again. You can write an Entrypoint Script which helps you with this.