wordpressdockerubuntudocker-composevolumes

Docker Compose for WordPress Containers Fails to Mount Local Volumes with ${PWD} Paths in Ubuntu/AWS


I'm encountering an issue with Docker Compose on an Ubuntu server (AWS) where it fails to mount local volumes despite using ${PWD} paths in the docker-compose.yml file. The setup involves a WordPress site with separate volumes for the database and WordPress content. Here's the relevant part of my docker-compose.yml:


volumes:
  data-db:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ${PWD}/storage/data-db
  data-wp:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ${PWD}/storage/data-wp

I've verified the directories /home/ubuntu/storage/data-db and /home/ubuntu/storage/data-wp exist and have appropriate permissions:

drwxr-xr-x 2 ubuntu root 4096 Mar 31 23:08 storage/data-db
drwxr-xr-x 2 ubuntu root 4096 Mar 31 23:08 storage/data-wp

When running the command sudo docker-compose -f ubuntu-container-bundle.yml up -d && docker-compose -f ubuntu-container-bundle.yml logs -f, I receive the following error:

Error response from daemon: failed to populate volume: error while mounting volume '/var/lib/docker/volumes/ubuntu_data-db/_data': failed to mount local volume: mount /storage/data-db:/var/lib/docker/volumes/ubuntu_data-db/_data, flags: 0x1000: no such file or directory

It's perplexing because the error message suggests Docker is trying to mount from /storage/data-db instead of the specified absolute path. I've tried the following to troubleshoot:

Despite these efforts, the error persists. Is there a caching issue with Docker Compose, or am I missing something in my volume configuration? How can I resolve this mounting issue?

Note: I'm doing this from /home/ubuntu/. When I build the wp container just using a simple reference like:

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

It messed up my SSH server access. I did I little research and seems to be a conflict with root user - not sure yet. Anyway, that's why I'm trying to set the directories and even tried to put all the build files (yml and dockerfiles) in a separate directory (/home/ubuntu/build-files-wp) but it's also returning me the same error.

Config


Solution

  • Use . rather than ${PWD}.

    version: '3.8'
    services:
      wordpress:
        image: wordpress
        ports:
          - 8080:80
        volumes:
          - data-wp:/var/www/html
        environment:
          - WORDPRESS_DB_HOST=db
          - WORDPRESS_DB_USER=wordpress
          - WORDPRESS_DB_PASSWORD=password
          - WORDPRESS_DB_NAME=wordpress
      db:
        image: mysql:5.7
        volumes:
          - data-db:/var/lib/mysql
        environment:
          MYSQL_DATABASE: wordpress
          MYSQL_USER: wordpress
          MYSQL_PASSWORD: password
    volumes:
      data-db:
        driver: local
        driver_opts:
          type: none
          o: bind
          device: ./storage/data-db
      data-wp:
        driver: local
        driver_opts:
          type: none
          o: bind
          device: ./storage/data-wp