0

I'm trying to set up a docker-compose file for running Apache Guacamole.

The compose file has 3 services, 2 for guacamole itself and 1 database image. The problem is that the database has to be initialized before the guacamole container can use it, but the files to initialize the database are in the guacamole image. The solution I came up with is this:

version: "3"
services:
  init:
    image: guacamole/guacamole:latest
    command: ["/bin/sh", "-c", "cp /opt/guacamole/postgresql/schema/*.sql /init/" ]
    volumes:
      - dbinit:/init    

  database:
    image: postgres:latest
    restart: unless-stopped
    volumes:
      - dbinit:/docker-entrypoint-initdb.d        
      - dbdata:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: guac
      POSTGRES_PASSWORD: guac
    depends_on:
      - init

  guacd:
    image: guacamole/guacd:latest
    restart: unless-stopped

  guacamole:
    image: guacamole/guacamole:latest
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      GUACD_HOSTNAME: guacd
      POSTGRES_HOSTNAME: database
      POSTGRES_DATABASE: guac
      POSTGRES_USER: guac
      POSTGRES_PASSWORD: guac
    depends_on:
      - database
      - guacd

volumes:
  dbinit:
  dbdata:

So I have one container whose job is to copy the database initialization files into a volume and then I mount that volume in the database. The problem is that this creates a race condition and is ugly. Is there some elegant solution for this? Is it possible to mount the files from the guacamole image into the database container? I would rather avoid having an extra sql file with the docker-compose file.

Thanks in advance!

Nathan
  • 1
  • 1
  • If the config file is a dependency of the db containers, why not copy it to the host and keep it adjacent to the compose file. All other solutions seems overly complex for such an easy problem. – Mansoor Feb 03 '21 at 00:14
  • I have a feeling you're right! I just wanted to see if this was possible. Thanks. – Nathan Feb 03 '21 at 16:27
  • I'm sure you can mount some common fs/network-drive to both containers, or establish a bridge network and use scp to copy the file across, but both are unnecessarily complicated. – Mansoor Feb 03 '21 at 17:06

0 Answers0