News for hackers. Stuff that matters.
Re:Docker at Spotify by boothead on Thursday January 09, 2014 @07:14AM (#7029993)
Here's my docker file for running a postgres 9.3 with plv8

    FROM    boothead/saucy

    ENV     DEBIAN_FRONTEND noninteractive

    # Add repository and install PostgreSQL 9.3
    RUN     echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main 9.3" >> /etc/apt/sources.list
    RUN     apt-get update
    RUN     apt-get -y --force-yes -f install postgresql-9.3 postgresql-client-9.3 libicu48 wget

    RUN     wget http://www.mirrorservice.org/sites/archive.ubuntu.com/ubuntu//pool/universe/libv/libv8/libv8-3.7.12.22_3.7.12.22-3_amd64.deb
    RUN     dpkg -i libv8-3.7.12.22_3.7.12.22-3_amd64.deb
    RUN     apt-get -y --force-yes -f install postgresql-9.3-plv8


    # Postgres is started now, shut it down and replace config
    RUN     service postgresql stop
    ADD     pg_hba.conf     /etc/postgresql/9.3/main/
    ADD     pg_ident.conf   /etc/postgresql/9.3/main/
    ADD     postgresql.conf /etc/postgresql/9.3/main/

    # Create superuser, tempo db and plv8 language
    ADD     create_user.sh /
    RUN     /bin/bash /create_user.sh
    RUN     rm /create_user.sh

    # Configure for running in container
    EXPOSE  5432
    # VOLUME ["/var/lib/postgresql/9.3/main"]
    CMD     ["/bin/su", "postgres", "-c", "/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf"]
create_user.sh is basically service postgresql start; su echo <SQL> | psql; service postgresql stop;

This is fine for me to spin up a postgres instance at some known state for development, but it's a bit dissatisfying for managing the data separately from the container. Anyone got any tips for integrating volumes with this?

Re:Docker at Spotify by sehrope on Thursday January 09, 2014 @08:14AM (#7030234)
I've been trying out Docker recently but haven't tried running persistent services in it yet (only long running programs like apps). From what I've gathered so far, Docker allows you to specify volumes (via -v /host/path:/container/path) that are mounted directly and don't get included in the container's copy-on-write filesystem (basically shared directories with the host). You can use this to pass data into the container (ex: a SQL file to init your schema) or pass data out of the container (ex: the DB files themselves or the logs). I've been using the latter to centralize Dokku logs[1].

To split out the Postgres setup and the initial schema setup, one idea might be to have a the CMD for the container run a script to automatically check for a bootstrap file on startup and run it. The bootstrap file could be specified via a volume mount. To use the container with a different dev setup (i.e. a different bootstrap SQL script) you'd simply start up the container with the shared directory pointing somewhere else.

If you want to save the Postgres data files themselves outside of the container you can again do it with volume mounts but you'll need some way to keep track of which goes where. The volume mounts are specified each time you startup the container so you need something to save those. For Dokku specifically there's the PG plugin and it looks like it does exactly this[2]. I haven't use it but I guess it validates the idea.

This seems like a general trend with Docker; it's really cool tech but it's pretty low level so you need something atop it to make usage smoother.

[1]: https://github.com/sehrope/dokku-logging-supervisord

[2]: https://github.com/Kloadut/dokku-pg-plugin/blob/master/comma...