Docker Community Forums

Share and learn in the Docker community.

How to add Docker volume via YAML file in such a way that it will work?


(Shsunix) #1

I’ve containerized a mail server with Docker and mounted the volumes which contains MySQL database, home path for the mail storage and log files. It works with any of the container of same image when attached with preexisting data volumes.

However, there’s a restriction that volumes should be attached to only one container at a time otherwise, It will throw an error like can’t connect to database.

I’ve created a Docker compose YAML file and stacked it for load balancing as well as scaling purposes which will replicate my image instances twice as mentioned in the file and will respawn when container get destroyed. Replicas of containers are running but like the native one without the volumes data taking in from the file.

YAML file is below.

version: "3"
services:
mail:
image: shsunix/testindimail:latest
volumes:
- “/docklogs:/var/log/indimail”
- “/indimailbox:/home/mail”
- "/indidatabase:/var/indimail"
deploy:
replicas: 2
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- “25:25”
- “110:110”
- “143:143”
- “465:465”
- “587:587”
- “993:993”
- "995:995"
networks:
- webnet
networks:
webnet:


(Sriharsha22) #2

Hey are you able to solve the issue. I’m facing the same problem. Let me know if you know any path to resolve.