Skip to main content
Help us improve Python packaging – donate today!

Create and start MySQL/PostgreSQL containers with a single management command

Project Description

Create and start MySQL/PostgreSQL containers with a single management command.

  • If an image isn’t available, it will be pulled.
  • If a container with the specified configuration doesn’t exist, it will be created.
  • If a container is not running, it will be started.

Necessary settings are taken from settings.py.

  • SQLite databases are ignored.
  • For MySQL and PostgreSQL, one container is created per database.

Also, Docker settings are picked up from standard DOCKER_* environment variables.

Usage

./manage.py db_quick_setup

'db_quick_setup' should be added to INSTALLED_APPS:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'db_quick_setup'
)

'HOST' in database settings should point to Docker hostname/IP. You can use find_docker_host() to auto-detect it.

from db_quick_setup import find_docker_host

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mysql_db',
        'USER': 'mysql_db',
        'PASSWORD': 'mysql_db_pass',
        'HOST': find_docker_host(),
        'PORT': 53308
    }
}

'NAME', 'USER', 'PASSWORD' and 'PORT' can have arbitrary values, the container will be configured accordingly.

  • For MySQL 'NAME' and 'USER' should have the same value, it’s a limitation of the official image.

Settings

DOCKER_MYSQL_IMAGE: Docker image to use for MySQL databases. Default is the official image - mysql:latest.

DOCKER_POSTGRES_IMAGE: Docker image for PostgreSQL databases. Default is the official image - postgresql:latest.

DOCKER_ASSERT_HOSTNAME: enable SSL hostname validation (boolean). True by default.

DOCKER_PRIVILEGED: create privileged containers. Currently used as a workaround for permission problems on Travis CI. It is disabled by default, and shouldn’t be enabled usually.

Release history Release notifications

This version
History Node

0.0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-db-quick-setup-0.0.2.tar.gz (8.4 kB) Copy SHA256 hash SHA256 Source None Sep 20, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page