rudak
rudak

Reputation: 389

Portainer - how to add local path to a volume in docker compose

I'm trying to do a basic configuration with Portainer but I can't get my volumes to connect properly. I'm trying a relatively simple configuration as you can see but I get an error when I try this:

version: '3'

networks:
  frontend:
  backend:
    
services:
  app:
    image: webdevops/apache:alpine
    container_name: app
    volumes:
      - "/my/host/absolute/path/data: /var/www"
    networks:
    - frontend
  php:
    image: php:fpm-alpine
    container_name: php
    networks:
      - backend
  db:
    image: mariadb
    container_name: db
    volumes:
      - "/my/host/absolute/path/storage: /var/lib/mysql"
    networks:
      - backend

Could you give me a hand to make this configuration work which would make me a good little starting point to learn to setup the rest correctly.
All I can find in the documentation is how to link named volumes but I don't see how to link them to a folder on my local computer so I'm not really advanced with this information...

Upvotes: 1

Views: 11324

Answers (1)

PaulCrp
PaulCrp

Reputation: 978

Use "/var/lib..."

You need to create a volume and after you can access it by using /var/lib/docker/volumes/myVolume/_data

If you are on Windows and you use wsl$ go to your file explorer and use this path : \\wsl.localhost\docker-desktop-data\version-pack-data\community\docker\volumes to find all your existing volumes. You can past every file you want in your volumes and access it in Portainer.

if you follow this steps, you're exemple should look like:

version: '3'

networks:
  frontend:
  backend:

services:
  app:
    image: webdevops/apache:alpine
    container_name: app
    volumes:
      - "/var/lib/docker/volumes/myAppVolume/_data: /var/www"
    networks:
    - frontend
  php:
    image: php:fpm-alpine
    container_name: php
    networks:
      - backend
  db:
    image: mariadb
    container_name: db
    volumes:
      - "/var/lib/docker/volumes/myStorageVolume/_data: /var/lib/mysql"
    networks:
      - backend

Upvotes: 0

Related Questions