skip to Main Content

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

4

Answers


  1. try something like this - ${PWD}/:/var/www/html

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
  3. I tried ${PWD} --> C:/path(example) in docker-compose.yml file. This works for me. (Windows 10)

    Login or Signup to reply.
  4. Another cause of this issue is being cded into a subdirectory of the Docker project. Just cd into the same directory as the docker-compose.yml file and try again.

    Example:

    dotan@deathstar:~/project/docker-services/php$ docker-compose up --build -d
    ... Lots of lines here ...
    Successfully built 0e9ea46affe0
    Successfully tagged foobar_php:latest
    Creating foobar_mysql_1 ... done
    Creating foobar_php_1   ... error
    ERROR: for foobar_php_1  Cannot create container for service php: create .: volume name is too short, names should be at least two alphanumeric characters
    ERROR: for php  Cannot create container for service php: create .: volume name is too short, names should be at least two alphanumeric characters
    ERROR: Encountered errors while bringing up the project.
    
    dotan@deathstar:~/project/docker-services/php$ cd ../..
    
    dotan@deathstar:~/project/$ docker-compose up --build -d
    ... Lots of lines here ...
    Successfully built 0e9ea46affe0
    Successfully tagged foobar_php:latest
    Creating foobar_mysql_1 ... done
    Creating foobar_php_1   ... done
    Creating foobar_nginx_1 ... done
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search