December 1, 2015
CEO at ctrlweb
@danidou
https://ca.linkedin.com/in/dleblanc78
YulDev Organizer
Montréal-Django Organizer
Symfony Montréal Co-organizer
Laravel Montréal Co-organizer
daniel@ctrlweb.ca
Learn the basic principles behind Docker
Learn a few neat tricks to build a working Django dev environment
And that's about it!
Creates and runs Docker containers.
Runtime instance of a
Docker image.
"Recipe" to build a container. Stateless and never changes. Shared via the Docker Hub.
Hosted registry service for managing images. The "GitHub" of Docker images.
Parentless images. Docker images can "extend" other Docker images.
Defines multi-container applications.
Docker allows you to package an application with all of its dependencies into a standardized unit for software development.
- Docker website
WORKS ON MY MACHINE!
Nope
Yup
Nope
Yup
(a side adventure!)
VS
Large
Small
Size (drive space)
Startup speed
Fast
Slow
Interaction
Very easy
Complicated
Memory footprint
Tiny
Large
Versioning
Each container
Whole VM
It's just a different tool altogether!
It can be very useful!
http://tinyurl.com/docker-vs-vagrant
If you want to manage machines, you should use Vagrant. And if you want to build and run applications environments, you should use Docker.
Let's
Yup
$ docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating s... 2729 [OK]¶
[...]
$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
2332d8973c93: Downloading [=================> ] 23.25 MB/65.67 MB
ea358092da77: Download complete
[...]
Search for an image in Docker Hub
Create a container from a Docker Image
$ docker run -it ubuntu /bin/bash
root@c2bb2bc1e0e8:/#
Run a command within a container
$ docker-compose build
db uses an image, skipping
Building app...
Step 0 : FROM python:3.3
---> d6f2c2d52f99
[...]
$ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------
ctrlwebca_app_1 python3 manage.py runserve ... Exit 137
ctrlwebca_db_1 /docker-entrypoint.sh postgres Exit 0
Build an application's containers
List an application's containers
$ docker-compose up -d
Starting ctrlwebca_db_1...
Starting ctrlwebca_app_1...
Create and start an application's containers
autodock:
image: prologic/autodock
restart: always
ports:
- "1338:1338/udp"
- "1338:1338/tcp"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
autodocklogger:
image: prologic/autodock-logger
restart: always
links:
- autodock
autodockhipache:
image: prologic/autodock-hipache
restart: always
links:
- autodock
- hipache:redis
hipache:
image: tutum/hipache
restart: always
ports:
- 80:80
- 443:443
< Docker automation daemon
< Docker events logger
< Automatic Hipache VirtualHost
< Distributed HTTP & WS proxy
$ docker-compose up -d
And that's it! You have a micro PaaS server running on your machine!
FROM python:3.3
ENV PYTHONBUFFERED 1
ENV APPLICATION_ROOT /code
RUN mkdir -p $APPLICATION_ROOT
WORKDIR $APPLICATION_ROOT
ADD requirements.txt $APPLICATION_ROOT/
RUN pip install -r requirements.txt
ADD . $APPLICATION_ROOT/
Dockerfile
Django
psycopg2
requirements.txt
app:
build: .
expose:
- "80"
links:
- db
volumes:
- .:/code
command: python3 manage.py runserver 0.0.0.0:80
environment:
VIRTUALHOST: montreal-django.local
db:
image: postgres
docker-compose.yml
$ docker-compose run app django-admin.py startproject tutorial .
Starting dockertutorial_db_1...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
$ docker-compose up -d
Starting dockertutorial_db_1...
Starting dockertutorial_app_1...
currently in free beta