Embracing the Messiness in Search of Epic Solutions

Docker: Defining Custom Location for Named Volume

Posted

in

PROBLEM

Let’s assume we have the following docker-compose.yml:

version: '2'

services:
  jenkins:
    image: "jenkinsci/jenkins"
    ports:
    - "8080:8080"
    volumes:
    - jenkins:/var/jenkins_home

volumes:
  jenkins:

By the default, all Docker-managed named volumes are stored under the installed Docker directory… typically, /var/lib/docker/volumes/[path].

However, it is possible /var mount is low on disk space.

SOLUTION

It appears we can create a custom location for the given named volume:-

version: '2'

services:
  jenkins:
    image: "jenkinsci/jenkins"
    ports:
    - "8080:8080"
    volumes:
    - jenkins:/var/jenkins_home

volumes:
  jenkins:
    driver_opts:
    type: none
    device: /data/jenkins
    o: bind

Keep in mind /data/jenkins must be created first on the host.

Tags:

Comments

2 responses to “Docker: Defining Custom Location for Named Volume”

  1. Alexander Avatar
    Alexander

    Excellent! Thanks a lot!

  2. Scott Yannitell Avatar

    Awesome! Thank you!

Leave a Reply