This project makes heavy use of docker both in development and in production. This document contains snippets that are useful for accomplishing various tasks with docker.
Normally you'll use fab devup
and fab devup:quick
to start/stop your local docker containers,
but sometimes you need more fine grained control.
To fully delete an image you can run
docker rm [container id or name]
For example, docker rm etoolsinfra_db_1
should remove the db container.
After you do this you will need to rebuild it (typically with fab devup
).
To run just a single container, use the following:
docker-compose -f docker-compose.dev.yml up db
If you want to run it in the background, just add -d
docker-compose -f docker-compose.dev.yml up -d db
You can stop it with docker stop
. E.g.
docker stop etoolsinfra_db_1
Useful in case you've started a bunch of stuff in the background.
docker stop $(docker ps -a -q)
Sometimes you just want to rebuild an image in place - e.g. if you make changes to the proxy config file. You can do this with:
docker-compose -f docker-compose.dev.yml build [container name]
E.g.
docker-compose -f docker-compose.dev.yml build [container name]
See this gist for some useful cleanup commands. In particular, when frequently rebuilding the DB container, the following can be very useful for reclaiming disk space:
docker volume ls -qf dangling=true | xargs -r docker volume rm
UNICEF's dev/demo/staging infrastructure runs on docker cloud.
While most things can be managed in the cloud UI, it's nice to be able to troubleshoot environments on the command line.
To do that you first have to setup docker-cloud CLI.
Don't forget to add these two lines to your .bashrc
to avoid having to enter them every time:
export DOCKER_ID_USER=[your username]
export DOCKERCLOUD_NAMESPACE=unicef
From there you can use the standard CLI options. Some useful commands:
docker login
docker-cloud container ps
docker-cloud exec [container id]
or if bash
is installed
docker-cloud exec [container id] bash
Note that you must use container ids (e.g. "6b9e2155") and not names ("haproxy-dev-1").
You can get the ids from docker-cloud container ps
.
Some walkthroughs for doing things in docker cloud.
To setup the Docker cloud infrastructure to automatically redeploy a container when new changes appear on a branch, take the following steps:
1. Create a Trigger in Docker cloud
- Navigate to the service you want to setup. E.g. the dev web service.
- On the "General" tab under "Triggers" add a new trigger.
- You can name it something like
[stack]-[container]-redeploy
, e.g.dev-web-redeploy
- In the dropdown select "Redeploy"
- Click the "plus sign" to add it
- Note the URL that gets generated, you'll need this in the next step
2. Configure the Trigger in Docker Hub
- Now in Docker Hub find the appropriate repository E.g. the backend repo.
- On the "Webhooks" tab, click the "plus sign" to add a new webhook
- You can name it the same thing you named the Trigger
- In the Webhook URL paste the URL from above prefixed with https://cloud.docker.com.
- Click "Save"
3. Test
You can test by pushing a new commit to the appropriate branch and confirming it gets updated in docker cloud.