Docker for Development
Making your development workflows better
What is Docker ?
Docker allows you to package an application with all of its dependencies into a standardized unit for software development.
Docker is not a Virtual Machine
VMs vs. Docker
Virtual Machine
Docker
Why docker ?
- Speed
- Reproducible environments
- Portability
- Flexibility
- Minimal use of server resources
- Isolation
- Lightweight
Why are Docker Containers Lightweight?
Docker Performance
Booting 15 Openstack VMs
Basic Components
- Containers
- Images
- Registry
- Dockerfiles
- Volumes
Docker Image
Container
Base Image (Debian, CentOS, Alpine)
PHP Installed
Composer Installed
Drush added
Extensions installed
Runtime file system (read-write)
Dockerfile
FROM ubuntu
MAINTAINER MajuAnsari <majua@mindfiresolutions.com>
RUN apt-get update \
&& apt-get install -y php php5.6-sqlite php5.6-curl php5.6-gd
COPY configs/php-fpm.conf /etc/php/
WORKDIR /app
COPY . /app
CMD ./run.sh
docker build -t my_first_image .
Docker Hub / Registry
Public repository of docker images
~100
Official Images
400k+
User Images
https://quay.io/ - private repos
$ docker run -d -p 81:80 nginx:latest tail -f /var/log/nginx/access.log
Running a Container
Common arguments:
- -e set environment variables
- --expose expose ports to linked containers
- -p bind ports to host
- -v mount a volume
- -d run in detached mode
- lots more...
$ docker run -d -p 81:80 nginx:latest tail -f /var/log/nginx/access.log
Running a Container
Managing images/containers
docker images
View all images on your system
docker ps [-a]
View running or all containers
docker rm [tag/hash]
Delete a container
docker rmi [hash]
Delete an image
Multi-container apps
PHP
MySQL
Nginx
Redis
Containers can be linked together by Docker daemon
Multi-container apps
MySQL
docker run --name db --expose 3306 -d mysql
Redis
docker run --name redis --expose 6379 -d redis
PHP
docker run --name php --expose 9000 -d --link redis:redis --link db:db php
Nginx
docker run --name nginx -p 81:80 -d --link php:php -v ./src:/var/www nginx
Docker Compose
- Define containers in a single file
- Spin them up with one command
- Shut them down with one command
A tool for defining and running multi-container applications with Docker
docker-compose.yml
version: '2'
services:
php-fpm:
image: php-fpm
expose:
- "9000"
links:
- redis
- mysql
nginx:
image: nginx
ports:
- "81:80"
links:
- php-fpm
mysql:
image: mysql
expose:
- “3306”
redis:
image: redis
docker-compose up [-d]
- Download any images
- Build images if needed
- Launch containers in order
- Link containers together
Managing images
docker-compose ps
View current containers for project
docker-compose stop [app]
Stop any or all running containers
docker-compose rm [app]
Delete a container
docker-compose build [app]
Force a re-build of an image
DEMO
Docker Workflow
Docker Ideologies
- Single process per image
-
Keep images lightweight
- Use small base images
- Install minimum packages
- Combine commands
- Configuration via environment variables
- Trash & rebuild
- Treat containers as ephemeral entities
- Don't connect to containers directly
- Store data in volumes
Questions ?
Thank you
&
Use Docker
Email - majua@mindfiresolutions.com
Twitter - @majuansari
Github - majuansari
Docker presentation
By Maju Ansari
Docker presentation
- 1,246