Docker-compose: Mount a volume only in the first container

I’m using docker compose to run a MariaDB Galera Cluster, where each node is a docker container, but MariaDB GC need a master node at start to initialize the database.

I’d like to choose the master container by mounting a file as a volume in the container, with a script at start which check for this file. So I need docker-compose to mount the file only for the first container launched and not for the container created by doing docker-compose scale.

  • Docker how to create container
  • Jenkinsfile Pipeline do something when some checked-in file is changed / newly checked out / run in a fresh node
  • Location of docker images downloaded by Docker (1.9.1) on Mac OS X
  • Why use a data-only container over a host mount?
  • Accessing node_modules after npm install inside Docker
  • How can I share a network interface with docker without setns error?
  • Is it possible ?

  • How to put docker image created through save command to remote registry without docker client
  • Tensorflow image_retraining:retrain in docker is not found
  • Running a docker image on dokku
  • Execution is overlapped nodes created by docker selenium grid and distribution with testNG data provider how avoid this?
  • When I issue the docker images command there is a “Repository” column — is this correct?
  • Issue on deploying single cartridge app on Stratos
  • One Solution collect form web for “Docker-compose: Mount a volume only in the first container”

    What you want to do is not directly possible; when using docker-compose scale you will get a suite of identical containers. You have several options available for selecting a primary node for your Galera cluster. Here are two; there are undoubtedly others:

    Explicit primary

    Have the primary be a single-instance container in your docker-compose.yaml file, and only scale the secondary containers.

        image: myimage
        command: command_to_start_galera_master
      image: myimage
        - galera_primary
      command: command_to_start_galera_worker

    Dynamic primary

    If you’re willing to write some code, you could probably use etcd to perform master election, probably by taking advantage of the ability to atomically create keys.

    I don’t have an example of this handy, but the process should be relatively simple:

    • Each node attempts to create a particular key in etcd
    • The node that succeeds is the master
    • Other nodes can query etcd for the address of the master
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.