the “right” way to manage docker database schemas

I am developing an open source application consisting of a Java web application and a postgresql database. Ideally, it will be deployed similarly to the process described in detail in the quick start of the shipyard :

  • run data container
  • run DB container
  • run application container

Recommended time to set up your database schema? I was thinking of creating a Docker file for the database image that creates the schema when it is built, but postgres is not working at this time, obviously.

+6
source share
1 answer

We use Postgres and Docker, where I work, and we finished the following:

At the top of docker -entrypoint.sh, I add the following:

# Get the schema url=$(curl -s -u ${GIT_USER}:${GIT_PASSWORD} "${SQL_SCRIPT_URL}" | python -c 'import sys, json; print json.load(sys.stdin)["download_url"]') curl ${url} > db.sh chmod +x db.sh cp db.sh ./docker-entrypoint-initdb.d 

Basically the shell script from Github is loaded, which initializes the schema for the database. We do this for version control of the circuit, so when you start your container, you can tell which circuit to use with the ENV variable.

Some notes about the code:

  • We need to reorganize to pull stuff out of Github using a private key instead of user credentials.
  • Catalog. / docker -entrypoint-initdb.d is the place where docker -entrypoint.sh will look for starting init scripts for the database. You can move files to this place as you want. Do this if downloading from Github is not applicable.
+3
source

Source: https://habr.com/ru/post/982954/


All Articles