Docker Community Forums

Share and learn in the Docker community.

Define custom volume locations for Docker

I was wondering to set all volumes inside a folder ‘./Docker’, and organize it as: ./Docker/apache ./Docker/mariabd

docker-compose.yml

version: "3.9"

# Networks
networks:
  # Internal network
  internal:
    driver: bridge

# Volumes
volumes:
  # MariaDB and PHPmyAdmin volume
  mariadb_data:
  phpmyadmin_data:
  apache_data:
  php_data:
    driver: local # set .Docker/

services:
    shopping:
        build: 
            args: 
                user: john
                uid: 1000
            context: ./
            dockerfile: Dockerfile
        image: shopping-app
        restart: unless-stopped
        working_dir: /var/www/
        volumes:
            - ./:/var/www
        depends_on: 
            - apache
            - mariadb
            - phpmyadmin
        environment:
            - COMPOSER_VERSION=1
            - WEB_ALIAS_DOMAIN=localhost
            - WEB_DOCUMENT_ROOT=/app/pub     
        networks: 
            - internal
 
    apache:
      container_name: shopping-apache
      image: webdevops/apache:alpine
      restart: always
      networks:
        - internal
      working_dir: /var/www/app
      volumes:
        - .:/var/www/app
      #depends_on:
        #- php
      environment:
        - WEB_DOCUMENT_ROOT=/var/www/app/public
        - XDEBUG_MODE=debug
      expose:
        - 9003
      ports:
        - 80:80
  
    mariadb:
      image: mariadb:10.6.5 #mariadb:latest
      restart: always
      container_name: shopping-mariadb
      networks:
        - internal
      working_dir: /var/www/app
      volumes:
        - mariadb_data:/var/lib/mysql
        - .:/var/www/app/
      environment:
        - MYSQL_DATABASE=shopping
        - MYSQL_PASSWORD=root
        - MYSQL_ROOT_PASSWORD=root
      ports:
        - 3306:3306

I changed the topic title from “Define volune for Docker”. It was too general and had a typo in it

If bind mount is not enough, you could try some plugins too: Docker Hub

Or create a virtual disk and use that as a volume.

1 Like