I Believe

  • All humans are equal,

Docker stacks and bundles

Docker Stacks and Distributed Application Bundles are experimental features introduced in Docker 1.12 and Docker Compose 1.8, alongside the concept of swarm mode, and Nodes and Services in the Engine API.

Startup-Init

We can use autodock as a daemon for Docker automation. Start by running the autodock daemon:

$ docker run -d --name autodock prologic/autodock

Followed by linking the plugin:

$ docker run -d --link autodock prologic/autodock-cron

Now whenever you create a new container autodock will listen for Docker events and discover containers that have been created. The autodock-cron plugin will specifically listen for created containers that have a CRON environment variable and schedule a job based on the cron expression supplied and re-run that container when its scheduled has triggered.

Start a “Hello” Busybox Container:

$ docker run --name hello -e CRON="*/1 * * * *" busybox sh -c 'echo Hello'

Now autodock-cron will schedule a timer to re-run this container every minute until the container is deleted and removed.. After about three minutes or so you should see the following in the logs:

$ docker logs hello
Hello
Hello
Hello

You can also use hypersh to run cron jobs against containers you’ve brought online via the hyper service. This is in beta, and the documentation can be found here

Serve assets with S3 and Cloudfront

Amazon makes it very easy to communicate with their AWS services. In our case, we’re using the packages django-storage-redux and boto to make a connection with the S3 bucket, and to read from the Cloudfront domain. The environment variables are as follows:

  • DJANGO_AWS_ACCESS_KEY_ID
  • DJANGO_AWS_SECRET_ACCESS_KEY
  • DJANGO_AWS_STORAGE_BUCKET_NAME
  • DJANGO_CLOUDFRONT_DOMAIN

Static file storage is also automatically set to the configured S3 bucket, and bringing up the production environment, docker-entrypoint.sh will run collectstatic, ensuring the most up to date files are added to the bucket and served from the CDN.

Reference

Generate Django secret key:

python -c 'import random; print "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'

Build image:

$ docker-compose build
$ docker-compose build --no-cache   # build without cache

See processes:

$ docker-compose ps    # docker-compose processes
$ docker ps -a        # docker processes
$ docker stats <container name>   # see live docker container metrics

Remove all docker containers:

$ docker rm $(docker ps -a -q)

Remove all docker images:

$ docker rmi $(docker images -q)

List dangling volumes:

$ docker volume ls -qf dangling=true

Remove all dangling volumes:

docker volume ls -qf dangling=true | xargs -r docker volume rm

Remove all containers, images, and networks created by the docker-compose up command:

$ docker-compose -f docker-compose.yml down --rmi all

Invoke task list:

  • clean
    • Clean’s *.pyc files
  • build
    • #TODO
  • dev_start
    • Bring the containers up with the dev compose file in detached mode
  • dev_start_build
    • Builds and brings the containers up with the dev compose file in detached mode
  • dev_start_show
    • Bring the containers up in the shell with the dev compose file
  • dev_stop
    • Stops all containers
  • prod_start
    • Bring up containers in the prod environment in detached mode
  • prod_start_build
    • Build and brings the containers up in the prod environment in detached mode
  • prod_start_show
    • Bring the containers up in the shell
  • prod_stop
    • Bring down the containers
  • start_shell
  • start_psql
  • start_bash
  • migrate
    • Run migrate on the web container
  • backup_db
    • Backup current postgresql database
  • list_backups
    • Lists all postgresql backups
  • rm_all_containers
    • Restart fresh
  • rm_all_images
    • Remove all trash images