pro100tom
pro100tom

Reputation: 165

Docker compose host volume directory empty

I have run docker-compose up -d command but volume directories are empty on host.

  1. Ubuntu 20.04
  2. docker-compose up -d
  3. page is displayed in the browser as expected
  4. docker volume inspect shows this:
    {
        "CreatedAt": "2020-08-29T22:26:49+01:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/magento-sandbox_magento_data/_data",
        "Name": "magento-sandbox_magento_data",
        "Options": null,
        "Scope": "local"
    }
]
  1. Image: https://hub.docker.com/r/bitnami/magento/
  2. yml file (/home/tomas/Documents/Projects/Magento/magento-sandbox):
version: '2'
services:
  mariadb:
    image: 'docker.io/bitnami/mariadb:10.3-debian-10'
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - MARIADB_USER=tomas
      - MARIADB_PASSWORD=tomas
      - MARIADB_DATABASE=magento_sandbox
    volumes:
      - 'mariadb_data:/home/tomas/Documents/Projects/Magento/magento-sandbox/db'
  magento:
    image: 'docker.io/bitnami/magento:2-debian-10'
    environment:
      - MARIADB_HOST=mariadb
      - MARIADB_PORT_NUMBER=3306
      - MAGENTO_DATABASE_USER=tomas
      - MAGENTO_DATABASE_PASSWORD=tomas
      - MAGENTO_DATABASE_NAME=magento_sandbox
      - ELASTICSEARCH_HOST=elasticsearch
      - ELASTICSEARCH_PORT_NUMBER=9200
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - 'magento_data:/home/tomas/Documents/Projects/Magento/magento-sandbox/webroot'
    depends_on:
      - mariadb
      - elasticsearch
  elasticsearch:
    image: 'docker.io/bitnami/elasticsearch:6-debian-10'
    volumes:
      - 'elasticsearch_data:/home/tomas/Documents/Projects/Magento/magento-sandbox/elasticsearch/data'
volumes:
  elasticsearch_data:
    driver: local
  mariadb_data:
    driver: local
  magento_data:
    driver: local
  1. All containers are running (docker ps command verifies this)

Why my /home/tomas/Documents/Projects/Magento/magento-sandbox/webroot is empty? I mean why mountpoint is not reflecting the configuration in the file?

How to achieve the result where this directory contains all the files used to render the page in the browser?

Upvotes: 0

Views: 2051

Answers (2)

pro100tom
pro100tom

Reputation: 165

I have managed to find the problem and it turned out to be multiple ones.

  1. As pointed out I had incorrect mounting paths
  2. I have changed my docker paths too, however they should have been left unchanged. I didn't know these must be as defined in the first place
  3. Once I fixed the first two issues I needed to double check the directories I have used for the host needed to be empty or non-existing at all (not sure if this was an issue, but when I made sure it was empty it worked)
  4. My elasticsearch build was failing so it prevented further webroot development

I have fixed all of these and it worked. However after all up and running, my elasticsearch failed again but this is another issue and is not related to this one.

Thank you, guys, for your support and effort.

Upvotes: 0

xddq
xddq

Reputation: 381

Uhm you did create volumes but you did not asign any source paths to them. So they are stored in the default path. (under ubuntu I know it is /var/lib/docker/volumes/HERE). Anyway you will have to find out where the data you want to mount is stored on the docker machines. (you normally set the paths in dockerfiles)

Anyway, the correct syntax is

/path/to/host/machine:/path/in/container/machine

Once you have found that out go ahead and create a .env file in your diretory where your container and compose is stored. It contains

HOST_BASE_DATA_PATH=/home/tomas/Documents/Projects/Magento/magento-sandbox
MAGENTO_DATA_PATH=/insert/the/path/inside/the/magento/container
ELASTICSEARCH_DATA_PATH=/insert/the/path/inside/the/elastic/container
MARIADB_DATA_PATH=/insert/the/path/inside/the/mariadb/container

We will use these variable to get a somehwat cleaner docker-compose file.

In your compose we will specify volumes using the following attributes: ( I hope one example makes it clear enough)

mariadb:
    image: 'docker.io/bitnami/mariadb:10.3-debian-10'
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - MARIADB_USER=tomas
      - MARIADB_PASSWORD=tomas
      - MARIADB_DATABASE=magento_sandbox
    volumes:
      - type: bind
        # where it will be stored on the host machine
        source: ${HOST_BASE_DATA_PATH}/mariadb
        # where it is stored on the docker container
        target: ${MARIADB_DATA_PATH}

greetings

Upvotes: 2

Related Questions