Docker is a useful abstraction for processes
- Web application server (django/rails/tomcat/...)
- Database
- Reverse HTTP proxy (nginx/apache)
... each in their own Docker container
This allows a process to package all its code/binaries, libraries and configuration in a portable package.
Why dockerise your service?
- Remove platform dependencies (essential OS parts are packaged with your app)
- Simplify installation / running (
docker pull
, thendocker run ...
) - Manage external dependencies (control over files/directories, network ports, databases and other dependent processes)
- Make Dev like Prod (develop locally with a full app stack, without complex install and management)
- Linux: https://docs.docker.com/engine/installation/
- Windows/OS X: use docker toolbox
Or run these commands (Ubuntu):
sudo apt-get update
sudo apt-get -y install apt-transport-https
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo sh -c "echo 'deb https://apt.dockerproject.org/repo ubuntu-$(lsb_release -cs) main' > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get -y install docker-engine
sudo apt-get -y install curl
sudo bash -c "curl -L https://github.com/docker/compose/releases/download/1.6.0-rc2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose"
sudo chmod u+x /usr/local/bin/docker-compose
sudo docker-compose -v
</section>
Create + start
sudo docker run -d \
--name wiki \
--rm \
-p 80:8080 \
mazzolino/tiddlywiki:latest
Stop + destroy
sudo docker stop wiki
See what it's doing (here)[https://github.com/djmaze/tiddlywiki-docker/blob/master/Dockerfile]
Create + start
sudo docker run -d \
--name wiki \
--restart always \
-p 80:8080 \
-v /srv/docker/wiki:/var/lib/tiddlywiki \
mazzolino/tiddlywiki:latest
Stop + destroy (but don't lose the data!)
sudo docker stop wiki
sudo docker rm wiki
</section>
docker-compose.yml
web:
container_name: wiki
image: mazzolino/tiddlywiki
restart: always
volumes:
- /srv/docker/wiki:/var/lib/tiddlywiki
Start/stop
sudo docker-compose up -d
sudo docker-compose down
</section>
reverse-proxy.yml
proxy:
container_name: proxy
image: jwilder/nginx-proxy
restart: always
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /srv/ssl:/etc/nginx/certs:ro
ports:
- 80:80
# Assumes you have certs in place
#- 443:443
</section>
wiki.yml
web:
container_name: wiki
image: mazzolino/tiddlywiki
restart: always
volumes:
- /srv/docker/wiki:/var/lib/tiddlywiki
environment:
- VIRTUAL_HOST=wiki.$DOMAIN
- VIRTUAL_PORT=8080
</section>
In the same directory as the docker-compose.yml
file, run:
export DOMAIN=example.com
sudo docker-compose -f proxy.yml up -d
sudo docker-compose -f wiki.yml up -d
To shutdown and destroy the containers, run:
-
sudo docker-compose -f proxy.yml down
-
sudo docker-compose -f wiki.yml down
For quick and easy docker containers:
- Get a wildcard SSL certificate (~$55 https://ssl2buy.com )
- Get a cheap domain (~$3/yr https://godaddy.com )
- Use Wildcard DNS to forward all requests to a single IP
- Use container
jwilder/nginx-proxy
for automatic HTTPS routing