SlideShare a Scribd company logo
Running Docker in Development & Production (DevSum 2015)
Who?
@Ben_Hall
Tech Support > Tester > Developer > Founder >
Freelancer
Agenda
• Introduction To Docker & Containers
• Dockerizing Dockerising Applications
• Docker As Development Environment
• Testing Containers
• Production
A Load Balanced
ASP.NET/NancyFX/Node.js Website
running inside Docker
https://www.dropbox.com/s/gbcifo094c9v8ar/nancy-lb-demo-optimised.gif?dl=0
WHAT ARE CONTAINERS?
Virtual Machine
https://www.docker.com/whatisdocker/
Container
https://www.docker.com/whatisdocker/
Container
Container
Own Process Space
Own Network Interface
Own Root Directories
Sandboxed
Like a lightweight VM. But it’s not a VM.
Container
Native CPU
Native Memory
Native IO
No Pre-Allocation
Instant On
Zero Performance Overheard
Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)
Build, Ship and Run Any App, Anywhere
Docker - An open platform for distributed applications
for developers and sysadmins.
Running Docker in Development & Production (DevSum 2015)
RUNNING CONTAINERS
ElasticSearch Before Docker
> curl -L -O http://download.elasticsearch.org/PATH/TO/VERSION.zip
> unzip elasticsearch-$VERSION.zip
> cd elasticsearch-$VERSION
The only requirement for installing Elasticsearch is a recent version of Java. Preferably,
you should install the latest version of the official Java from www.java.com.
1. Download the jre-8u40-macosx-x64.dmg file.
2. Review and agree to the terms of the license agreement before downloading the
file.
3. Double-click the .dmg file to launch it
4. Double-click on the package icon to launch install Wizard
5. The Install Wizard displays the Welcome to Java installation screen. Click Next
6. Oracle has partnered with companies that offer various products. After ensuring
the desired programs are selected, click the Next button to continue the
installation.
7. After the installation has completed, a confirmation screen appears. Click Close to
finish the installation process.
> ./bin/elasticsearch
Running Docker in Development & Production (DevSum 2015)
> docker run -d #Run In Background
dockerfile/elasticsearch #Image Name
https://www.dropbox.com/s/fbe8briq6ayycrh/start-elastic.gif?dl=0
> docker run -d
-p 9200:9200 -p 9300:9300 #Bind Ports
dockerfile/elasticsearch
curl b2d:9200 ?
> boot2docker ip
192.168.59.103
> echo “192.168.59.103 b2d” >> /private/etc/hosts
> cat /private/etc/hosts
192.168.59.103 b2d
for i in {49000..49900}; do
VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i";
VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port$i,udp,,$i,,$i";
done
Installing In Development
https://github.com/boot2docker/
https://github.com/docker/machine
DOCKERISING YOUR APPLICATIONS
Dockerfile
Dockerfile &
App Source
Build
Image
https://docs.docker.com/reference/builder/
Running Docker in Development & Production (DevSum 2015)
FROM
FROM ubuntu:14.01 # Base Image
FROM ubuntu:latest # Caution
COPY / WORKDIR / RUN
COPY . /src # Copy current directory into image
WORKDIR /src # Set working directory
RUN apt-get update # Run a shell command
EXPOSE
EXPOSE 3000 # Allow binding to port 3000
EXPOSE 7000-8000 # Expose range of ports
CMD
CMD ./bin/www # Default command when container
starts
Complete .NET/Mono Dockerfile
FROM benhall/docker-mono
COPY . /src
WORKDIR /src
RUN xbuild Nancy.Demo.Hosting.Docker.sln
EXPOSE 8080
CMD ["mono",
"src/bin/Nancy.Demo.Hosting.Docker.exe"]
benhall/docker-mono Dockerfile
FROM ubuntu:14.01
MAINTAINER Ben Hall "ben@benhall.me.uk"
RUN apt-get update -qq && 
apt-get -yqq install mono-complete && 
apt-get -yqq clean
> docker build #Build Image
-t scrapbook/app:20150520 #Image Name:Tag
. #Directory
https://www.dropbox.com/s/k7h0tdu28160nil/scrapbook-node-build-optimised.gif?dl=0
Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)
> cat .dockerignore #Ignore file in root
all_the_passwords.txt
.git/
node_modules/
bower_components/
> docker run -it #Run In Foreground
scrapbook/app:20150520 #Image Name:Tag
> docker run -it
-p 3000 #Bind Random Port to Port 3000
scrapbook/app:20150520
> docker run -it
-p 3000:3000 #Bind Known Port
scrapbook/app:20150520
> docker ps #List Running Processes
-a #Include Stopped
CONTAINER ID IMAGE
COMMAND CREATED
STATUS PORTS
NAMES
1e5b37b0a2bc scrapbook/app:20150520133000
"npm start" 4 minutes ago
Up 4 minutes 0.0.0.0:49176->3000/tcp
mad_fermi
> docker logs # Stream logs
1e5b37b0a2bc # ContainerID
> docker run -d -p 9200:9200 -p 9300:9300
--name es # Friendly Name
dockerfile/elasticsearch
> docker run –it –p 3000
--link es:elasticsearch # Link
container:alias
scrapbook/app:20150520
> cat /etc/hosts
172.17.0.79 elasticsearch
> env
HOSTNAME=2f3b959b13a0
ELASTICSEARCH_PORT=tcp://172.17.0.79:9200
ELASTICSEARCH_PORT_9200_TCP=tcp://172.17.0.79:9200
ELASTICSEARCH_PORT_9200_TCP_ADDR=172.17.0.79
ELASTICSEARCH_PORT_9200_TCP_PORT=9200
ELASTICSEARCH_PORT_9200_TCP_PROTO=tcp
ELASTICSEARCH_NAME=/scrapbookv2_web_1/es
NODE_ENV=production
> docker run –it –p 3000 --link es:elasticsearch
-e SQLSERVER=10.10.20.50 #Environment Variable
scrapbook/app:20150520
> env
SQLSERVER.10.10.20.50
HOSTNAME=2f3b959b13a0
ELASTICSEARCH_PORT=tcp://172.17.0.79:9200
ELASTICSEARCH_PORT_9200_TCP=tcp://172.17.0.79:9200
ELASTICSEARCH_PORT_9200_TCP_ADDR=172.17.0.79
ELASTICSEARCH_PORT_9200_TCP_PORT=9200
ELASTICSEARCH_PORT_9200_TCP_PROTO=tcp
ELASTICSEARCH_NAME=/scrapbookv2_web_1/es
NODE_ENV=production
http://12factor.net/
http://blog.benhall.me.uk/2015/05/using-make-to-manage-docker-image-creation/
> make build
NAME = benhall/docker-make-demo
default: build
build:
docker build -t $(NAME) .
debug:
docker run --rm -it $(NAME) /bin/bash
run:
docker run --rm $(NAME)
push:
docker push $(NAME)
release: build push
> cat docker-compose.yml
web: # Container Name
build: . # Build
links: # Links
- elasticsearch
ports: # Ports
- 3000
environment: # Environment
VIRTUAL_HOST: 'app.joinscrapbook.com'
NODE_ENV: 'production'
elasticsearch: # 2nd Container Name
# Use Image
image: dockerfile/elasticsearch:latest
ports: # Ports
- 9200:9200
> docker-compose up # Start containers
–d # In background
Recreating scrapbookv2_nginx_1...
Recreating scrapbookv2_redis_1...
Recreating scrapbookv2_db_1...
Recreating scrapbookv2_elasticsearch_1...
Recreating scrapbookv2_web_1…
> docker-compose stop # Stop containers
Stopping scrapbookv2_web_1...
Stopping scrapbookv2_elasticsearch_1...
Stopping scrapbookv2_db_1...
Stopping scrapbookv2_redis_1...
Stopping scrapbookv2_nginx_1...
Sidekick Container For Testing
> docker run –d # No need to bind ports
--name es # Friendly Name
dockerfile/elasticsearch
> docker run –it
--link es:es # Link
Container:alias
benhall/curl # Curl Image
curl http://es:9200 # Ping service
> echo $? # Exit Code
0 # Success
Schema Management Containers
> docker run –d # No need to bind ports
--name es # Friendly Name
dockerfile/elasticsearch
> docker run –rm
--link es:es # Link
Container:alias
myapp/schema:latest # Schema Image
Running Docker in Development & Production (DevSum 2015)
Tagging
ubuntu 15.04 2427658c75a1 12 weeks ago 117.5 MB
ubuntu vivid 2427658c75a1 12 weeks ago 117.5 MB
ubuntu vivid-20150218 2427658c75a1 12 weeks ago 117.5 MB
ubuntu 14.10 78949b1e1cfd 12 weeks ago 194.4 MB
ubuntu utopic-20150211 78949b1e1cfd 12 weeks ago 194.4 MB
ubuntu utopic 78949b1e1cfd 12 weeks ago 194.4 MB
ubuntu latest 2d24f826cb16 12 weeks ago 188.3 MB
ubuntu trusty 2d24f826cb16 12 weeks ago 188.3 MB
ubuntu 14.04 2d24f826cb16 12 weeks ago 188.3 MB
ubuntu 14.04.2 2d24f826cb16 12 weeks ago 188.3 MB
ubuntu trusty-20150218.1 2d24f826cb16 12 weeks ago 188.3 MB
ubuntu 12.04 1f80e9ca2ac3 12 weeks ago 131.5 MB
ubuntu precise 1f80e9ca2ac3 12 weeks ago 131.5 MB
ubuntu precise-20150212 1f80e9ca2ac3 12 weeks ago 131.5 MB
ubuntu 12.04.5 1f80e9ca2ac3 12 weeks ago 131.5 MB
ubuntu 14.04.1 5ba9dab47459 3 months ago 188.3 MB
> docker push # Push Image To Remote Registry
benhall/nancy-demo:latest # Image Name:Tag
> docker export # Export Image to Tar
containerid # Container ID
> container.tar # Name of Tar
> docker run -p 5000:5000
registry:2.0 # Docker Registry Container
> docker push b2d:5000/aspnet:beta5
Recap
• Docker Client / Boot2docker
• Docker Daemon
• Docker Images
• Docker Container
• Docker Hub / Registry
DOCKER AS A DEVELOPMENT
ENVIRONMENT
ASP.NET vNext DNX
> cat Makefile
restore:
docker run -it -v /Users/ben/.dnx:/home/dev/.dnx
-v $(shell pwd)/WebApplication:/app -w="/app"
benhall/aspnet-vnext-npm dnu restore
build:
docker run -v /Users/ben/.dnx:/home/dev/.dnx -v $(shell
pwd)/WebApplication:/app -w="/app" benhall/aspnet-vnext-npm
dnu build
run:
docker run -it -v /Users/ben/.dnx:/home/dev/.dnx -v
$(shell pwd)/WebApplication:/app -w="/app" -p 5001
benhall/aspnet-vnext-npm dnx . kestrel
> docker run –it
--name scrapbook-iojs # Name it for future
-v $(pwd):/app
-v $(pwd)/iojs:/app/node_modules # Move location
-w="/app” # Set working directory
--entrypoint /bin/bash # Override entrypoint
iojs
GoLang
> cat Dockerfile
FROM golang:onbuild
> cat Makefile
NAME = ocelotuproar/docker-outdated
build:
docker build -t $(NAME) .
run:
docker run --rm --name $(INSTANCE) $(NAME)
> make build # Run Golang Compiler & Build
container
> make run # Run built application
Run Unit Tests Inside Containers
Run UI Inside Containers
> docker run -d -p 4444:4444 --name selenium-hub
selenium/hub:2.45.0
> docker run -d --link selenium-hub:hub selenium/node-
chrome:2.45.0
> docker run -d --link selenium-hub:hub selenium/node-
firefox:2.45.0
Private NPM Repository
https://github.com/BenHall/docker-local-npm-registry
> docker run -d -v $(pwd)/config.yaml:/opt/sinopia/config.yaml
-p 4873:4873
keyvanfatehi/sinopia:latest
> npm set registry http://b2d:4873
> npm adduser --registry http://b2d:4873
RStudio
• docker run -d -p 8787:8787 rocker/rstudio
PRODUCTION
> docker pull # Pull Image To Remote Registry
benhall/nancy-demo:latest # Image Name:Tag
Always include tag otherwise pulls everything
> cat docker-compose.yml
web:
build: .
links:
- elasticsearch
volumes: # Mount Directories Outside Container
- /opt/docker/scrapbook/db:/usr/src/app/ocelite-db
- /opt/docker/scrapbook/uploads:/usr/src/app/uploads
- /opt/docker/scrapbook/tmp:/usr/src/app/tmp
elasticsearch:
image: dockerfile/elasticsearch:latest
volumes: # Host:Container
- /opt/docker/scrapbook_elasticsearch:/data
Persisting Data
Port 80
Problematic Approach
> docker run -d --name nginx_root
--link blog_benhall-1:blog_benhall-1
--link scrapbook-1:scrapbook-1
--link scrapbook_web_1:scrapbook_web_1
--link brownbag_web_1:brownbag_web_1
-p 80:80
-v /opt/docker/nginx/www:/data
-v /opt/docker/nginx/sites:/etc/nginx/sites-enab
-v /opt/docker/nginx/logs:/var/log/nginx
dockerfile/nginx
Problems
• Static link
– /etc/hosts
• Adding new website? Reboot everything
• Requires nginx config for each site
Nginx Proxy
https://github.com/jwilder/nginx-proxy
https://www.dropbox.com/s/2f6y2frfjafc409/nginx-proxy-optimised.gif?dl=0
Running Docker in Development & Production (DevSum 2015)
• VIRTUAL_HOST=my.container.com
• -v /var/run/docker.sock:/tmp/docker.sock
Running Docker in Development & Production (DevSum 2015)
1) Docker raises events when containers start /
stop
2) Registrator listens to events adds the new
container’s details into Consul
3) Consul links container’s IP / Ports to DNS names
& discovery API
> ping redis.service.consul
4) Nginx uses Consul API to write & load config
A Load Balanced
ASP.NET/NancyFX/Node.js Website
running inside Docker
https://www.dropbox.com/s/gbcifo094c9v8ar/nancy-lb-demo-optimised.gif?dl=0
Installing In Production
'curl -sSL https://get.docker.com/ | sh'
Running Docker in Development & Production (DevSum 2015)
> docker run -d
--restart=always # Restart if exits
redis
Ports
> docker run –p 3000:3000 nodejs node.app
> sudo apt-get install ufw && sudo ufw disable
> sudo ufw default deny
> sudo ufw allow 22
> sudo ufw allow 80
> sudo ufw enable
Docker manages IPTables, ufw won’t block
> echo "DOCKER_OPTS=”--iptables=false"" >
/etc/default/docker
> docker run –p 127.0.0.1:3000 nodejs node.app
Memory / CPU Usage
> docker run –m 128m –cpu 50 mysql
Space Usage
Linux cgroups…
Bandwidth Usage
> iptables -A OUTPUT -p tcp --sport 80 -m state --
state ESTABLISHED,RELATED -m quota –quota 1310720
-j ACCEPT
Log Files
5.8M Mar 29 07:17 /var/lib/docker/containers/0e3bcd1
157M Mar 29 14:25 /var/lib/docker/containers/1922c7a
1.8M Mar 6 07:23 /var/lib/docker/containers/2774be7
32K Jan 14 16:18 /var/lib/docker/containers/38e7c4ae
183K Mar 17 10:00 /var/lib/docker/containers/4a207c6
955M Mar 29 14:25 /var/lib/docker/containers/5408f6a
1.3M Mar 6 10:17 /var/lib/docker/containers/6e41977
1.3M Mar 6 10:11 /var/lib/docker/containers/756f64b
71 Jan 28 11:50 /var/lib/docker/containers/b1a2d887e
509M Mar 29 14:25 /var/lib/docker/containers/c5784ce
16K Feb 2 18:26 /var/lib/docker/containers/daa45ceb
488K Mar 6 10:43 /var/lib/docker/containers/ec80d6a
Handling Machine Name Changes
• Couchbase
• InfluxDB
THE FUTURE?
Docker and Microsoft Partnership
SQL Server as a Container?
Spoon.NET
Visual Studio as a Container?
Docker as a Platform
Running Docker in Development & Production (DevSum 2015)
http://www.joinscrapbook.com
IN SUMMARY…
Only tool I use for deployment
• Close gap between development and
production
• Everything is a container!
• Running platforms like Logstash, ElasticSearch,
Redis, EventStore, RavenDB, NancyFX etc?
Consider containers for deployment.
@Ben_Hall
Ben@BenHall.me.uk
Blog.BenHall.me.uk
Thank you
http://www.joinscrapbook.com

More Related Content

PPTX
Real World Experience of Running Docker in Development and Production
PPTX
Running Docker in Development & Production (#ndcoslo 2015)
PPTX
The How and Why of Windows containers
PPTX
Deploying Windows Containers on Windows Server 2016
PPTX
Real World Lessons on the Pain Points of Node.js Applications
PPTX
Running .NET on Docker
PPTX
Lessons from running potentially malicious code inside Docker containers
PPTX
Real World Lessons on the Pain Points of Node.JS Application
Real World Experience of Running Docker in Development and Production
Running Docker in Development & Production (#ndcoslo 2015)
The How and Why of Windows containers
Deploying Windows Containers on Windows Server 2016
Real World Lessons on the Pain Points of Node.js Applications
Running .NET on Docker
Lessons from running potentially malicious code inside Docker containers
Real World Lessons on the Pain Points of Node.JS Application

What's hot (20)

PPTX
Lessons from running potentially malicious code inside containers
PPTX
Deploying applications to Windows Server 2016 and Windows Containers
PDF
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
PDF
DCSF19 Tips and Tricks of the Docker Captains
PDF
JDO 2019: Tips and Tricks from Docker Captain - Łukasz Lach
PDF
手把手帶你學Docker 03042017
PDF
Docker All The Things - ASP.NET 4.x and Windows Server Containers
PPTX
PHP development with Docker
PDF
Developing and Deploying PHP with Docker
PPTX
Dockerizing a Symfony2 application
PDF
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
PDF
Docker workshop 0507 Taichung
PDF
Docker perl build
PPT
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
PDF
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
PDF
Getting instantly up and running with Docker and Symfony
PDF
Introducing Docker
PDF
Docker in practice
PPTX
Docker orchestration v4
PDF
Docker security
Lessons from running potentially malicious code inside containers
Deploying applications to Windows Server 2016 and Windows Containers
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
DCSF19 Tips and Tricks of the Docker Captains
JDO 2019: Tips and Tricks from Docker Captain - Łukasz Lach
手把手帶你學Docker 03042017
Docker All The Things - ASP.NET 4.x and Windows Server Containers
PHP development with Docker
Developing and Deploying PHP with Docker
Dockerizing a Symfony2 application
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
Docker workshop 0507 Taichung
Docker perl build
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Getting instantly up and running with Docker and Symfony
Introducing Docker
Docker in practice
Docker orchestration v4
Docker security
Ad

Viewers also liked (9)

PPTX
Tips on solving E_TOO_MANY_THINGS_TO_LEARN with Kubernetes
PPTX
What Developers Need To Know About Visual Design
PPTX
Embracing Startup Life and learning to think The Startup Way
PPTX
Learning to think "The Designer Way"
PPTX
Beginners Guide to Kontena
PDF
Building High Availability Application with Docker
PDF
Visual studio 2017 Launch keynote - Afterworks@Noumea
PPTX
Architecting .NET Applications for Docker and Container Based Deployments
PDF
Scaling Docker with Kubernetes
Tips on solving E_TOO_MANY_THINGS_TO_LEARN with Kubernetes
What Developers Need To Know About Visual Design
Embracing Startup Life and learning to think The Startup Way
Learning to think "The Designer Way"
Beginners Guide to Kontena
Building High Availability Application with Docker
Visual studio 2017 Launch keynote - Afterworks@Noumea
Architecting .NET Applications for Docker and Container Based Deployments
Scaling Docker with Kubernetes
Ad

Similar to Running Docker in Development & Production (DevSum 2015) (20)

PDF
Containerizing a Web Application with Vue.js and Java
PDF
Docker, the Future of DevOps
PPTX
Docker - A Ruby Introduction
PPTX
Docker Ecosystem on Azure
PDF
Docker for developers on mac and windows
PDF
Docker in everyday development
PPTX
Docker - Demo on PHP Application deployment
PPSX
Docker and containers - Presentation Slides by Priyadarshini Anand
PDF
Be a better developer with Docker (revision 3)
PPTX
PDF
Streamline your development environment with docker
PPTX
Tribal Nova Docker workshop
PPTX
Docker Basics
PDF
Docker From Scratch
PDF
Workshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
PDF
Introduction to Docker, December 2014 "Tour de France" Edition
PDF
Docker Intro
PPTX
Docker Container As A Service - JAX 2016
PPTX
Docker intro
Containerizing a Web Application with Vue.js and Java
Docker, the Future of DevOps
Docker - A Ruby Introduction
Docker Ecosystem on Azure
Docker for developers on mac and windows
Docker in everyday development
Docker - Demo on PHP Application deployment
Docker and containers - Presentation Slides by Priyadarshini Anand
Be a better developer with Docker (revision 3)
Streamline your development environment with docker
Tribal Nova Docker workshop
Docker Basics
Docker From Scratch
Workshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
Introduction to Docker, December 2014 "Tour de France" Edition
Docker Intro
Docker Container As A Service - JAX 2016
Docker intro

More from Ben Hall (17)

PPTX
The Art Of Documentation - NDC Porto 2022
PPTX
The Art Of Documentation for Open Source Projects
PPTX
Three Years of Lessons Running Potentially Malicious Code Inside Containers
PPTX
Containers without docker
PPTX
Deploying windows containers with kubernetes
PPTX
The Art of Documentation and Readme.md for Open Source Projects
PPTX
How Secure Are Docker Containers?
PPTX
The Challenges of Becoming Cloud Native
PPTX
Scaling Docker Containers using Kubernetes and Azure Container Service
PPTX
The art of documentation and readme.md
PPTX
Experimenting and Learning Kubernetes and Tensorflow
PPTX
Learning Patterns for the Overworked Developer
PPTX
Implementing Google's Material Design Guidelines
PPTX
The Art Of Building Prototypes and MVPs
PPTX
Node.js Anti Patterns
PPTX
What Designs Need To Know About Visual Design
PPTX
Real World Lessons On The Anti-Patterns of Node.JS
The Art Of Documentation - NDC Porto 2022
The Art Of Documentation for Open Source Projects
Three Years of Lessons Running Potentially Malicious Code Inside Containers
Containers without docker
Deploying windows containers with kubernetes
The Art of Documentation and Readme.md for Open Source Projects
How Secure Are Docker Containers?
The Challenges of Becoming Cloud Native
Scaling Docker Containers using Kubernetes and Azure Container Service
The art of documentation and readme.md
Experimenting and Learning Kubernetes and Tensorflow
Learning Patterns for the Overworked Developer
Implementing Google's Material Design Guidelines
The Art Of Building Prototypes and MVPs
Node.js Anti Patterns
What Designs Need To Know About Visual Design
Real World Lessons On The Anti-Patterns of Node.JS

Recently uploaded (20)

PPTX
Online Work Permit System for Fast Permit Processing
PPTX
Mini project ppt template for panimalar Engineering college
PPT
JAVA ppt tutorial basics to learn java programming
PPTX
FLIGHT TICKET RESERVATION SYSTEM | FLIGHT BOOKING ENGINE API
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
top salesforce developer skills in 2025.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
System and Network Administration Chapter 2
PPTX
Essential Infomation Tech presentation.pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
How Creative Agencies Leverage Project Management Software.pdf
Online Work Permit System for Fast Permit Processing
Mini project ppt template for panimalar Engineering college
JAVA ppt tutorial basics to learn java programming
FLIGHT TICKET RESERVATION SYSTEM | FLIGHT BOOKING ENGINE API
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
top salesforce developer skills in 2025.pdf
Transform Your Business with a Software ERP System
Which alternative to Crystal Reports is best for small or large businesses.pdf
System and Network Administration Chapter 2
Essential Infomation Tech presentation.pptx
How to Migrate SBCGlobal Email to Yahoo Easily
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Softaken Excel to vCard Converter Software.pdf
ManageIQ - Sprint 268 Review - Slide Deck
How to Choose the Right IT Partner for Your Business in Malaysia
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
VVF-Customer-Presentation2025-Ver1.9.pptx
Materi_Pemrograman_Komputer-Looping.pptx
Digital Strategies for Manufacturing Companies
How Creative Agencies Leverage Project Management Software.pdf

Running Docker in Development & Production (DevSum 2015)

  • 2. Who? @Ben_Hall Tech Support > Tester > Developer > Founder > Freelancer
  • 3. Agenda • Introduction To Docker & Containers • Dockerizing Dockerising Applications • Docker As Development Environment • Testing Containers • Production
  • 4. A Load Balanced ASP.NET/NancyFX/Node.js Website running inside Docker https://www.dropbox.com/s/gbcifo094c9v8ar/nancy-lb-demo-optimised.gif?dl=0
  • 8. Container Own Process Space Own Network Interface Own Root Directories Sandboxed Like a lightweight VM. But it’s not a VM.
  • 9. Container Native CPU Native Memory Native IO No Pre-Allocation Instant On Zero Performance Overheard
  • 12. Build, Ship and Run Any App, Anywhere Docker - An open platform for distributed applications for developers and sysadmins.
  • 15. ElasticSearch Before Docker > curl -L -O http://download.elasticsearch.org/PATH/TO/VERSION.zip > unzip elasticsearch-$VERSION.zip > cd elasticsearch-$VERSION The only requirement for installing Elasticsearch is a recent version of Java. Preferably, you should install the latest version of the official Java from www.java.com. 1. Download the jre-8u40-macosx-x64.dmg file. 2. Review and agree to the terms of the license agreement before downloading the file. 3. Double-click the .dmg file to launch it 4. Double-click on the package icon to launch install Wizard 5. The Install Wizard displays the Welcome to Java installation screen. Click Next 6. Oracle has partnered with companies that offer various products. After ensuring the desired programs are selected, click the Next button to continue the installation. 7. After the installation has completed, a confirmation screen appears. Click Close to finish the installation process. > ./bin/elasticsearch
  • 17. > docker run -d #Run In Background dockerfile/elasticsearch #Image Name https://www.dropbox.com/s/fbe8briq6ayycrh/start-elastic.gif?dl=0
  • 18. > docker run -d -p 9200:9200 -p 9300:9300 #Bind Ports dockerfile/elasticsearch
  • 19. curl b2d:9200 ? > boot2docker ip 192.168.59.103 > echo “192.168.59.103 b2d” >> /private/etc/hosts > cat /private/etc/hosts 192.168.59.103 b2d for i in {49000..49900}; do VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i"; VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port$i,udp,,$i,,$i"; done
  • 25. FROM FROM ubuntu:14.01 # Base Image FROM ubuntu:latest # Caution
  • 26. COPY / WORKDIR / RUN COPY . /src # Copy current directory into image WORKDIR /src # Set working directory RUN apt-get update # Run a shell command
  • 27. EXPOSE EXPOSE 3000 # Allow binding to port 3000 EXPOSE 7000-8000 # Expose range of ports
  • 28. CMD CMD ./bin/www # Default command when container starts
  • 29. Complete .NET/Mono Dockerfile FROM benhall/docker-mono COPY . /src WORKDIR /src RUN xbuild Nancy.Demo.Hosting.Docker.sln EXPOSE 8080 CMD ["mono", "src/bin/Nancy.Demo.Hosting.Docker.exe"]
  • 30. benhall/docker-mono Dockerfile FROM ubuntu:14.01 MAINTAINER Ben Hall "[email protected]" RUN apt-get update -qq && apt-get -yqq install mono-complete && apt-get -yqq clean
  • 31. > docker build #Build Image -t scrapbook/app:20150520 #Image Name:Tag . #Directory https://www.dropbox.com/s/k7h0tdu28160nil/scrapbook-node-build-optimised.gif?dl=0
  • 34. > cat .dockerignore #Ignore file in root all_the_passwords.txt .git/ node_modules/ bower_components/
  • 35. > docker run -it #Run In Foreground scrapbook/app:20150520 #Image Name:Tag
  • 36. > docker run -it -p 3000 #Bind Random Port to Port 3000 scrapbook/app:20150520
  • 37. > docker run -it -p 3000:3000 #Bind Known Port scrapbook/app:20150520
  • 38. > docker ps #List Running Processes -a #Include Stopped CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1e5b37b0a2bc scrapbook/app:20150520133000 "npm start" 4 minutes ago Up 4 minutes 0.0.0.0:49176->3000/tcp mad_fermi
  • 39. > docker logs # Stream logs 1e5b37b0a2bc # ContainerID
  • 40. > docker run -d -p 9200:9200 -p 9300:9300 --name es # Friendly Name dockerfile/elasticsearch > docker run –it –p 3000 --link es:elasticsearch # Link container:alias scrapbook/app:20150520 > cat /etc/hosts 172.17.0.79 elasticsearch > env HOSTNAME=2f3b959b13a0 ELASTICSEARCH_PORT=tcp://172.17.0.79:9200 ELASTICSEARCH_PORT_9200_TCP=tcp://172.17.0.79:9200 ELASTICSEARCH_PORT_9200_TCP_ADDR=172.17.0.79 ELASTICSEARCH_PORT_9200_TCP_PORT=9200 ELASTICSEARCH_PORT_9200_TCP_PROTO=tcp ELASTICSEARCH_NAME=/scrapbookv2_web_1/es NODE_ENV=production
  • 41. > docker run –it –p 3000 --link es:elasticsearch -e SQLSERVER=10.10.20.50 #Environment Variable scrapbook/app:20150520 > env SQLSERVER.10.10.20.50 HOSTNAME=2f3b959b13a0 ELASTICSEARCH_PORT=tcp://172.17.0.79:9200 ELASTICSEARCH_PORT_9200_TCP=tcp://172.17.0.79:9200 ELASTICSEARCH_PORT_9200_TCP_ADDR=172.17.0.79 ELASTICSEARCH_PORT_9200_TCP_PORT=9200 ELASTICSEARCH_PORT_9200_TCP_PROTO=tcp ELASTICSEARCH_NAME=/scrapbookv2_web_1/es NODE_ENV=production
  • 43. http://blog.benhall.me.uk/2015/05/using-make-to-manage-docker-image-creation/ > make build NAME = benhall/docker-make-demo default: build build: docker build -t $(NAME) . debug: docker run --rm -it $(NAME) /bin/bash run: docker run --rm $(NAME) push: docker push $(NAME) release: build push
  • 44. > cat docker-compose.yml web: # Container Name build: . # Build links: # Links - elasticsearch ports: # Ports - 3000 environment: # Environment VIRTUAL_HOST: 'app.joinscrapbook.com' NODE_ENV: 'production' elasticsearch: # 2nd Container Name # Use Image image: dockerfile/elasticsearch:latest ports: # Ports - 9200:9200
  • 45. > docker-compose up # Start containers –d # In background Recreating scrapbookv2_nginx_1... Recreating scrapbookv2_redis_1... Recreating scrapbookv2_db_1... Recreating scrapbookv2_elasticsearch_1... Recreating scrapbookv2_web_1… > docker-compose stop # Stop containers Stopping scrapbookv2_web_1... Stopping scrapbookv2_elasticsearch_1... Stopping scrapbookv2_db_1... Stopping scrapbookv2_redis_1... Stopping scrapbookv2_nginx_1...
  • 46. Sidekick Container For Testing > docker run –d # No need to bind ports --name es # Friendly Name dockerfile/elasticsearch > docker run –it --link es:es # Link Container:alias benhall/curl # Curl Image curl http://es:9200 # Ping service > echo $? # Exit Code 0 # Success
  • 47. Schema Management Containers > docker run –d # No need to bind ports --name es # Friendly Name dockerfile/elasticsearch > docker run –rm --link es:es # Link Container:alias myapp/schema:latest # Schema Image
  • 49. Tagging ubuntu 15.04 2427658c75a1 12 weeks ago 117.5 MB ubuntu vivid 2427658c75a1 12 weeks ago 117.5 MB ubuntu vivid-20150218 2427658c75a1 12 weeks ago 117.5 MB ubuntu 14.10 78949b1e1cfd 12 weeks ago 194.4 MB ubuntu utopic-20150211 78949b1e1cfd 12 weeks ago 194.4 MB ubuntu utopic 78949b1e1cfd 12 weeks ago 194.4 MB ubuntu latest 2d24f826cb16 12 weeks ago 188.3 MB ubuntu trusty 2d24f826cb16 12 weeks ago 188.3 MB ubuntu 14.04 2d24f826cb16 12 weeks ago 188.3 MB ubuntu 14.04.2 2d24f826cb16 12 weeks ago 188.3 MB ubuntu trusty-20150218.1 2d24f826cb16 12 weeks ago 188.3 MB ubuntu 12.04 1f80e9ca2ac3 12 weeks ago 131.5 MB ubuntu precise 1f80e9ca2ac3 12 weeks ago 131.5 MB ubuntu precise-20150212 1f80e9ca2ac3 12 weeks ago 131.5 MB ubuntu 12.04.5 1f80e9ca2ac3 12 weeks ago 131.5 MB ubuntu 14.04.1 5ba9dab47459 3 months ago 188.3 MB
  • 50. > docker push # Push Image To Remote Registry benhall/nancy-demo:latest # Image Name:Tag
  • 51. > docker export # Export Image to Tar containerid # Container ID > container.tar # Name of Tar
  • 52. > docker run -p 5000:5000 registry:2.0 # Docker Registry Container > docker push b2d:5000/aspnet:beta5
  • 53. Recap • Docker Client / Boot2docker • Docker Daemon • Docker Images • Docker Container • Docker Hub / Registry
  • 54. DOCKER AS A DEVELOPMENT ENVIRONMENT
  • 55. ASP.NET vNext DNX > cat Makefile restore: docker run -it -v /Users/ben/.dnx:/home/dev/.dnx -v $(shell pwd)/WebApplication:/app -w="/app" benhall/aspnet-vnext-npm dnu restore build: docker run -v /Users/ben/.dnx:/home/dev/.dnx -v $(shell pwd)/WebApplication:/app -w="/app" benhall/aspnet-vnext-npm dnu build run: docker run -it -v /Users/ben/.dnx:/home/dev/.dnx -v $(shell pwd)/WebApplication:/app -w="/app" -p 5001 benhall/aspnet-vnext-npm dnx . kestrel
  • 56. > docker run –it --name scrapbook-iojs # Name it for future -v $(pwd):/app -v $(pwd)/iojs:/app/node_modules # Move location -w="/app” # Set working directory --entrypoint /bin/bash # Override entrypoint iojs
  • 57. GoLang > cat Dockerfile FROM golang:onbuild > cat Makefile NAME = ocelotuproar/docker-outdated build: docker build -t $(NAME) . run: docker run --rm --name $(INSTANCE) $(NAME) > make build # Run Golang Compiler & Build container > make run # Run built application
  • 58. Run Unit Tests Inside Containers
  • 59. Run UI Inside Containers > docker run -d -p 4444:4444 --name selenium-hub selenium/hub:2.45.0 > docker run -d --link selenium-hub:hub selenium/node- chrome:2.45.0 > docker run -d --link selenium-hub:hub selenium/node- firefox:2.45.0
  • 60. Private NPM Repository https://github.com/BenHall/docker-local-npm-registry > docker run -d -v $(pwd)/config.yaml:/opt/sinopia/config.yaml -p 4873:4873 keyvanfatehi/sinopia:latest > npm set registry http://b2d:4873 > npm adduser --registry http://b2d:4873
  • 61. RStudio • docker run -d -p 8787:8787 rocker/rstudio
  • 63. > docker pull # Pull Image To Remote Registry benhall/nancy-demo:latest # Image Name:Tag Always include tag otherwise pulls everything
  • 64. > cat docker-compose.yml web: build: . links: - elasticsearch volumes: # Mount Directories Outside Container - /opt/docker/scrapbook/db:/usr/src/app/ocelite-db - /opt/docker/scrapbook/uploads:/usr/src/app/uploads - /opt/docker/scrapbook/tmp:/usr/src/app/tmp elasticsearch: image: dockerfile/elasticsearch:latest volumes: # Host:Container - /opt/docker/scrapbook_elasticsearch:/data Persisting Data
  • 66. Problematic Approach > docker run -d --name nginx_root --link blog_benhall-1:blog_benhall-1 --link scrapbook-1:scrapbook-1 --link scrapbook_web_1:scrapbook_web_1 --link brownbag_web_1:brownbag_web_1 -p 80:80 -v /opt/docker/nginx/www:/data -v /opt/docker/nginx/sites:/etc/nginx/sites-enab -v /opt/docker/nginx/logs:/var/log/nginx dockerfile/nginx
  • 67. Problems • Static link – /etc/hosts • Adding new website? Reboot everything • Requires nginx config for each site
  • 70. • VIRTUAL_HOST=my.container.com • -v /var/run/docker.sock:/tmp/docker.sock
  • 72. 1) Docker raises events when containers start / stop 2) Registrator listens to events adds the new container’s details into Consul 3) Consul links container’s IP / Ports to DNS names & discovery API > ping redis.service.consul 4) Nginx uses Consul API to write & load config
  • 73. A Load Balanced ASP.NET/NancyFX/Node.js Website running inside Docker https://www.dropbox.com/s/gbcifo094c9v8ar/nancy-lb-demo-optimised.gif?dl=0
  • 74. Installing In Production 'curl -sSL https://get.docker.com/ | sh'
  • 76. > docker run -d --restart=always # Restart if exits redis
  • 77. Ports > docker run –p 3000:3000 nodejs node.app > sudo apt-get install ufw && sudo ufw disable > sudo ufw default deny > sudo ufw allow 22 > sudo ufw allow 80 > sudo ufw enable Docker manages IPTables, ufw won’t block > echo "DOCKER_OPTS=”--iptables=false"" > /etc/default/docker > docker run –p 127.0.0.1:3000 nodejs node.app
  • 78. Memory / CPU Usage > docker run –m 128m –cpu 50 mysql Space Usage Linux cgroups… Bandwidth Usage > iptables -A OUTPUT -p tcp --sport 80 -m state -- state ESTABLISHED,RELATED -m quota –quota 1310720 -j ACCEPT
  • 79. Log Files 5.8M Mar 29 07:17 /var/lib/docker/containers/0e3bcd1 157M Mar 29 14:25 /var/lib/docker/containers/1922c7a 1.8M Mar 6 07:23 /var/lib/docker/containers/2774be7 32K Jan 14 16:18 /var/lib/docker/containers/38e7c4ae 183K Mar 17 10:00 /var/lib/docker/containers/4a207c6 955M Mar 29 14:25 /var/lib/docker/containers/5408f6a 1.3M Mar 6 10:17 /var/lib/docker/containers/6e41977 1.3M Mar 6 10:11 /var/lib/docker/containers/756f64b 71 Jan 28 11:50 /var/lib/docker/containers/b1a2d887e 509M Mar 29 14:25 /var/lib/docker/containers/c5784ce 16K Feb 2 18:26 /var/lib/docker/containers/daa45ceb 488K Mar 6 10:43 /var/lib/docker/containers/ec80d6a
  • 80. Handling Machine Name Changes • Couchbase • InfluxDB
  • 82. Docker and Microsoft Partnership
  • 83. SQL Server as a Container?
  • 85. Visual Studio as a Container?
  • 86. Docker as a Platform
  • 90. Only tool I use for deployment • Close gap between development and production • Everything is a container! • Running platforms like Logstash, ElasticSearch, Redis, EventStore, RavenDB, NancyFX etc? Consider containers for deployment.