I would like to create an Apache container and mount current working directory as a volume in container, so I have this code:
volumes:
- ${DOCUMENT_ROOT}:/var/www/html
The value of ${DOCUMENT_ROOT} is a dot in .env
file:
DOCUMENT_ROOT=.
My docker-compose.yml
file is at the root of my project directory and in my project directory there is a .docker
directory.
I tried this 3 lines:
volumes:
- .:/var/www/html
volumes:
- ./:/var/www/html
volumes:
- ${DOCUMENT_ROOT}:/var/www/html
But I have this error:
Creating 7.4.x-webserver ... error ERROR: for 7.4.x-webserver Cannot
create container for service webserver: b'create .: volume name is too
short, names should be at least two alphanumeric characters'
ERROR: for webserver Cannot create container for service webserver:
b'create .: volume name is too short, names should be at least two
alphanumeric characters' ERROR: Encountered errors while bringing up
the project. Failed to deploy 'Compose: docker-compose.yml':
`docker-compose` process finished with exit code 1
The content of my docker-compose.yml
file:
version: "3"
services:
webserver:
build:
context: ./.docker/bin/webserver
container_name: '7.4.x-webserver'
restart: 'always'
ports:
- "${HOST_MACHINE_UNSECURE_HOST_PORT}:80"
- "${HOST_MACHINE_SECURE_HOST_PORT}:443"
links:
- mysql
volumes:
- ${DOCUMENT_ROOT}:/var/www/html
- ${PHP_INI}:/usr/local/etc/php/php.ini
- ${VHOSTS_DIR}:/etc/apache2/sites-enabled
- ${LOG_DIR}:/var/log/apache2
mysql:
build:
context: "./.docker/bin/${DATABASE}"
container_name: 'mysql'
restart: 'always'
ports:
- "${HOST_MACHINE_MYSQL_PORT}:3306"
volumes:
- ${MYSQL_DATA_DIR}:/var/lib/mysql
- ${MYSQL_LOG_DIR}:/var/log/mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'sc-phpmyadmin'
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
PMA_USER: ${MYSQL_USER}
PMA_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- '${HOST_MACHINE_PHPMYADMIN_PORT}:80'
volumes:
- ./.docker/sessions
redis:
container_name: 'sc-redis'
image: redis:latest
ports:
- "${HOST_MACHINE_REDIS_PORT}:6379"
.env:
###> docker ###
DOCUMENT_ROOT=.
VHOSTS_DIR=./.docker/config/vhosts
APACHE_LOG_DIR=./.docker/logs/apache2
PHP_INI=./.docker/config/php/php.ini
DATABASE=mysql8
MYSQL_DATA_DIR=./.docker/data/mysql
MYSQL_LOG_DIR=./.docker/logs/mysql
HOST_MACHINE_UNSECURE_HOST_PORT=80
HOST_MACHINE_SECURE_HOST_PORT=443
HOST_MACHINE_MYSQL_PORT=3306
HOST_MACHINE_PHPMYADMIN_PORT=8080
HOST_MACHINE_REDIS_PORT=6379
MYSQL_ROOT_PASSWORD=tiger
MYSQL_USER=docker
MYSQL_PASSWORD=docker
MYSQL_DATABASE=docker
###> docker ###
How to fix this error please ?
In advance, thank you for your help
try something like this - ${PWD}/:/var/www/html
I struggled with this a lot. The only change I made - added a forward slash. Worked.
As-Is
volumes:
- ${PWD}:/apps
To-Be
volumes:
- ${PWD}/:/apps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With