Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-compose failing to mount multiple named volumes

I'm using docker-compose to build my jenkins container here, and I can't get it to mount 2 named volumes onto 1 container. Here is what I have:

docker-compose.yml:

version: '2'
networks:
  nw:
    driver: bridge

volumes:
  jenkins-ansible:
  jenkins-data:

services:
  jenkins:
    image: jenkins
    ports:
      - "801:8080"
    volumes:
      - jenkins-ansible:/var/lib/ansible
      - jenkins-data:/var/jenkins_home
    networks:
      - nw

I run docker-compose up -d and the container starts fine, but when I BASH into the container, df -h only shows one mount, /var/jenkins_home.

If I comment out the -jenkins-data:/var/jenkins_home line, it mounts the ansible volume.

So why does it only mount one volume? I can't find any mention of only being allowed to mount one volume per container, but that is how it looks.

And what is so special about the jenkins-data mount that it mounts preferentially over the jenkins-ansible mount? (I've tried swapping the 2 mount lines over, no change)

thanks in advance,

Jim

like image 449
Jim ReesPotter Avatar asked Mar 29 '18 21:03

Jim ReesPotter


1 Answers

The volumes are mounted properly but they don't appear using df -h.

If you really want to see all the mounts you can do cat /proc/mounts inside the container and they will show:

/dev/sdb /var/jenkins_home ext4 rw,nosuid,nodev,relatime,data=ordered 0 0
/dev/sdb /var/lib/ansible ext4 rw,nosuid,nodev,relatime,data=ordered 0 0

You can also do docker inspect CONTAINER_NAME and look at the Mounts and you should see something like this:

    "Mounts": [
        {
            "Type": "volume",
            "Name": "tst1_jenkins-ansible",
            "Source": "/data/docker-data/volumes/tst1_jenkins-ansible/_data",
            "Destination": "/var/lib/ansible",
            "Driver": "local",
            "Mode": "rw",
            "RW": true,
            "Propagation": ""
        },
        {
            "Type": "volume",
            "Name": "tst1_jenkins-data",
            "Source": "/data/docker-data/volumes/tst1_jenkins-data/_data",
            "Destination": "/var/jenkins_home",
            "Driver": "local",
            "Mode": "rw",
            "RW": true,
            "Propagation": ""
        }
    ],
like image 112
Constantin Galbenu Avatar answered Nov 09 '22 16:11

Constantin Galbenu