Riding The Whale
@jochen_christ
IT Consultant && Software Developer
https://www.docker.com/what-container
DEV = TEST = PROD
Container vs VM
https://www.docker.com/what-container
Container = OS Virtualization
VM = Hardware Virtualization
Linux & Windows
Now go and install docker for your OS
Images and Containers
Now, it's time to play
docker pull ubuntu
docker images
docker run -it --rm ubuntu bash
# Now you can do things in your container
root@ada3108b4d6b:/# ps -auxwww
root@ada3108b4d6b:/# apt-get update && apt-get -y install curl
# CTRL-PQ -> Back to host
docker ps
docker stats
docker stop 552e864fbe70
Quit Terminal: Crtl-PQ
Stop Container: Stop Process (exit) or docker stop
docker run -d -p 27017:27017 --name mymongo --rm mongo
docker ps
# Run commands in running container
docker exec -d mymongo touch hello
docker exec -it mymongo bash
docker exec -it mymongo mongo
docker run -d -p 8081:8081 --link mymongo:mongo --rm mongo-express
open http://localhost:8081
https://docs.docker.com/engine/docker-overview/#docker-architecture
Let's Build a Full-Stack Application
Web-App
EmberJS frontend served by nginx
Service
Spring Boot Java Application
Database
MongoDB
FROM openjdk:8-jdk-alpine
# Add files to image
ADD build/libs/simple-todo-service-0.0.1-SNAPSHOT.jar app.jar
# expose a port (internally!)
EXPOSE 8080
# Specify where to find the mongo host
ENV SPRING_DATA_MONGODB_HOST mongo
# Command when container runs
# Use exec forms (array-style) to run as PID 1
ENTRYPOINT ["java", "-jar", "/app.jar"]
Dockerfile (for Java Application)
Build Command
git clone https://github.com/jochenchrist/simple-todo-service.git
docker build -t simple-todo-service .
docker run -d -p 8080:8080 --link mymongo:mongo --rm simple-todo-service
# Base image
FROM nginx:alpine
# Add the web application
ADD dist/ /usr/share/nginx/html
# A custom nginx configuration is required for single page applications
ADD default.conf /etc/nginx/conf.d/default.conf
Dockerfile (for Web Application)
Build Command
git clone https://github.com/jochenchrist/simple-todo-web.git
docker build -t simple-todo-web .
docker run -d -p 80:80 --rm simple-todo-web
Good Practices for Dockerfile
- Run only one process in a container
- Keep images as small as possible
- Minimize the number of layers
- Combine statements
- apt-get update && apt-get install -y curl git
- Use the cache (reuse layers!)
- Process (with PID 1) should stop gracefully with SIGTERM
Web-App
EmberJS frontend served by nginx
Service
Spring Boot Java Application
Database
MongoDB
Now we have a Full-Stack Application
Docker Compose
# docker-compose.yml
version: '3'
services:
web:
image: "simple-todo-web"
ports:
- "80:80"
service:
image: "simple-todo-service"
ports:
- "8080:8080"
networks:
- database
depends_on:
- mongo
mongo:
image: "mongo"
networks:
- database
monog-express:
image: "mongo-express"
networks:
- database
networks:
database:
docker-compose up -d
Docker Hub
Docker Hub
- Hosted Docker Registry
- Default
- Public and Private (paid) Repos
- Tight Integration with Github
docker login
docker tag todo-web jochenchrist/simple-todo-web
docker push jochenchrist/simple-todo-web
docker tag todo-service jochenchrist/simple-todo-service
docker push jochenchrist/simple-todo-service
Docker Swarm
for i in 1 2 3; do \
docker-machine create --driver digitalocean \
--digitalocean-image ubuntu-16-04-x64 \
--digitalocean-access-token $DOTOKEN \
--engine-opt experimental=true \
devnight-node-$i \
; done
for i in 1 2 3; do \
docker-machine ssh devnight-node-$i ufw disable \
; done
docker-machine ssh devnight-node-1 \
docker swarm init --advertise-addr $(docker-machine ip devnight-node-1)
# follow the join instructions for node-2 and node-3
eval $(docker-machine env devnight-node-1)
docker deploy --compose-file docker-compose-swarm.yml simple-todo-app
Facts
- Apache 2.0 Licence
- OCI compliant
- Written in Go
-
libcontainer as core technology
- namespaces (isolation)
- control groups (resource limits)
- UnionFS (layered file system)
Wait!
Don't use it in production!
Think about...
Security
Data Storage
Monitoring
Cluster
Cloud
Docker - Riding The Whale
By jochenchrist
Docker - Riding The Whale
Riding The Whale
- 315