SlideShare a Scribd company logo
Docker Workshop
Evans Ye
2014.10.13
Agenda
• Docker and underlying technologies
• Running Docker containers
• Building Docker images
• The official Docker hub
Docker workshop
Docker workshop
Containers offer faster automation
Docker Container
• A container is a group of isolated processes
– cgroups
– namespace
• Isolated processes run straight on the host
– native CPU performance
– minimal memory overhead
– minimal network performance overhead
7
CGroups
Cgroups (control groups)
• Linux kernel feature
• Groups of processes
• Resource limitations
– Like limits.conf
but the scope is a set of processes instead of uid/gid
• May be nested
Cgroups submodules
• memory
• CPU
• network IO
• disk IO
10
Namespaces
namespaces
• Linux kernel feature
• wrap particular global system resource in an
abstracted, isolated instance
• May be nested
Different kinds of namespaces
#TrendInsight
Running Docker Containers
Docker workshop
Run Docker container in boot2docker directly
Create a container with interactive shell
$ docker run -t -i base:centos62 /bin/bash
[root@4d8c4b81f6d7 /]# exit (exited)
$ -t, --tty
Allocate a pseudo-TTY
$ -i, --interactive
Keep STDIN open even if not attached
Check containers’ status
$ docker ps
(only running containers are shown)
$ docker ps –a
(all)
Reattach in stopped container
$ docker start -i 4d8c4b81f6d7
[root@4d8c4b81f6d7 /]#
or use docker exec instead
$ docker start 4d8c4b81f6d7
$ docker exec –ti 4d8c4b81f6d7 bash
[root@4d8c4b81f6d7 /]#
Take a look at Docker run command
$ docker run -t -i base:centos62 /bin/bash
Command + args
$ docker run base:centos62 /bin/cat /etc/hosts
Name a container
$ docker run -ti --name foo base:centos62 /bin/bash
$ docker ps -a
$ docker rm foo
destroy foo container
Destroy all containers
$ docker rm `docker ps --no-trunc -aq`
(except running containers, they must be stopped first)
$ docker rm -f `docker ps --no-trunc -aq`
(force destroy all containers)
Create ephemeral container
$ docker run -ti --rm base:centos62 /bin/bash
[root@4d8c4b81f6d7 /]# exit (destroyed upon exit)
$ docker ps -a
Ports forwarding (publish)
$ docker run -ti -p 80:80 base:centos62 /bin/bash
# yum install httpd
# echo "hello world" > /var/www/html/index.html
# service httpd start
$ curl localhost:80
What does Docker port forwarding do?
Windows / OS X
boot2docker
Container Container 80
80
27
Well, I need to
render it
in browsers…
How about this?
Windows / OS X
boot2docker
Container Container 80
80
80
Doable via Vagrant
$ vim Vagrantfile
The solution
Windows / OS X
boot2docker
Container Container 80
80
80
 Docker
port
forwarding Vagrant
port forwarding
More about Docker ports forwarding
$ docker run -ti -p 80:80 base:centos62 /bin/bash
• -p, --publish
Publish a container's port to the host
• format:
– ip:hostPort:containerPort (10.1.1.1:80:80)
– ip::containerPort (10.1.1.1::80)
– hostPort:containerPort (80:80)
Volume (like sync folder)
$ docker run -ti --name apache
-v /httpd-logs:/var/log/httpd base:centos62
/bin/bash
# touch /var/log/httpd/foo
$ ls /http-logs
Volume from other container
(useful to share data)
$ docker run -ti --volumes-from apache
base:centos62 /bin/bash
# ls /var/log/httpd
Link
$ docker run -ti --link apache:apache.trendmicro.com
base:centos62 /bin/bash
# cat /etc/hosts
• Exposes information from source container to recipient
container in two ways:
– Environment variables
– Updating the /etc/hosts file
• format:
– name:alias
useful in multi-node situation
12/25/2014
service
(hadoop-client)
data
(hadoop-client)
link
Docker in client/server mode
Windows / OS X
boot2docker
(Docker client)
Linux server
Docker Engine
Container Container
Server: bind Docker engine to a tcp port
$ docker -d -H 10.1.1.1:2375 -H
unix:///var/run/docker.sock
• -d, --daemon
daemon mode
• -H, --host
the socket(s) to bind in daemon mode
Docker client
$ export DOCKER_HOST=tcp://10.1.1.1:2375
$ docker images
$ docker run -ti --rm centos:centos6 /bin/bash
(start container on the server)
• Note:
– expose tcp port could let someone get root access to the host
– not recommended in open network
Running containers in background
(Detached mode)
$ hadoop=$(docker run -d -p 50070:50070
tmh6:centos62)
$ docker inspect $hadoop
40
Vagrant creates
Docker containers in
detached mode
Some other VM-like operations
$ docker stop $hadoop
$ docker start $hadoop
$ docker kill $hadoop
$ docker rm $hadoop
https://docs.docker.com/reference/commandline/cli/
#TrendInsight
Building Docker Images
43
There are two ways
to build docker
images
First: commit an existing container
• Do changes manually, then commit
 quick and dirty
 suitable for experiment
 might be deleted in the future
Second: Build from Dockerfile
• Dockerfile is a series of instructions
• Use "Docker build" command to build images
• pros:
– build images automatically by following instructions
– visible and easy to understand instructions
– enable Docker specific functions in the image
– repeatability
A sample httpd service Dockerfile
FROM base:centos62
COPY index.html /var/www/html/index.html
RUN yum -y install httpd
EXPOSE 80
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
Build
$ mkdir apache-server
$ cd apache-server
$ echo "our first docker image" > index.html
$ vi Dockerfile (paste the sample and save it)
$ docker build -t apache:0.1 ./
Build context
• docker build -t apache:0.1 ./
• ./ will be transferred to Docker daemon as build
context
• Must have a Dockerfile there
– ./Dockerfile
• DO NOT build at /
– docker build -t apache:0.1 /
Run the apache image
$ docker run -d --name apache apache:0.1
$ docker run -ti --rm --link apache:a01
base:centos62 /bin/bash
# curl $A01_PORT_80_TCP_ADDR
(you see how link and expose work together)
50
Use entrypoint to
bind a specific
executable to the
image
An httpd service example
FROM base:centos62
COPY index.html /var/www/html/index.html
RUN yum -y install httpd
EXPOSE 80
ENTRYPOINT ["/usr/sbin/httpd"]
CMD ["-D", "FOREGROUND"]
The difference
$ docker run -ti --rm apache:0.1 /bin/bash
# (get into the container)
$ docker run -ti --rm apache:0.2 /bin/bash
show httpd helper message
 the only thing you can do is to pass args to httpd
Make sure init script always being executed
FROM base:centos62
…
ENTRYPOINT ["init_wrapper_script"]
CMD ["default_args"]
https://docs.docker.com/articles/dockerfile_best-practices/
SHIPPING
CONTAINERS
Tagging an image
$ docker tag -h
• dockerhub.evansye.com/base:centos62
– REGISTRYHOST = dockerhub.evansye.com
– NAME = base
– TAG = centos62
#TrendInsight
The official Docker hub
Docker workshop
Redis
$ docker run -d --name some-redis redis
$ docker run -ti --rm --link some-redis:redis redis
/bin/bash
# redis-cli
-h $REDIS_PORT_6379_TCP_ADDR
-p $REDIS_PORT_6379_TCP_PORT
https://registry.hub.docker.com/_/redis/
MySQL
$ docker run -d --name some-mysql -e
MYSQL_ROOT_PASSWORD=demo mysql
$ docker run -it --link some-mysql:mysql --rm mysql sh -c 'exec
mysql
-h"$MYSQL_PORT_3306_TCP_ADDR"
-P"$MYSQL_PORT_3306_TCP_PORT"
-uroot
-p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
https://registry.hub.docker.com/_/mysql/
Jenkins
$ docker run -d -p 8080:8080 Jenkins
http://HOST_IP:8080
https://registry.hub.docker.com/_/jenkins/
Private Docker registry
$ docker run -d -p 5000:5000 registry
$ docker tag IMAGE HOST_IP:5000/NAME:TAG
$ docker push HOST_IP:5000/NAME:TAG
https://registry.hub.docker.com/_/registry/
#TrendInsight
Summary
Recap docker run
• we’ve learned:
– port forwarding
– volume mounting
– linking containers together
– running containers at remote
Recap docker build
• we’ve learned:
– how to write a Dockerfile
– how expose and link work together
– use entrypoint to bind a specific executable with image
– ship images to the registry
#TrendInsight
Q & A
Re-associate Vagrant with VM
• VBoxManage list vms
• cd .vagrant/machines/docker-
platform/virtualbox/
• touch id
• echo 33ca… > id

More Related Content

PDF
Vagrant and docker
DuckDuckGo
 
PDF
Vagrant + Docker provider [+Puppet]
Nicolas Poggi
 
PDF
Puppet and Vagrant in development
Adam Culp
 
PDF
Docker by Example - Basics
CodeOps Technologies LLP
 
PDF
A Hands-on Introduction to Docker
CodeOps Technologies LLP
 
PDF
Introducing Docker
Francesco Pantano
 
PDF
Docker by Example - Quiz
CodeOps Technologies LLP
 
PPTX
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05
dotCloud
 
Vagrant and docker
DuckDuckGo
 
Vagrant + Docker provider [+Puppet]
Nicolas Poggi
 
Puppet and Vagrant in development
Adam Culp
 
Docker by Example - Basics
CodeOps Technologies LLP
 
A Hands-on Introduction to Docker
CodeOps Technologies LLP
 
Introducing Docker
Francesco Pantano
 
Docker by Example - Quiz
CodeOps Technologies LLP
 
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05
dotCloud
 

What's hot (19)

PDF
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
dotCloud
 
PDF
Docker puebla bday #4 celebration
Ramon Morales
 
PDF
Introduction to docker
Wei-Ting Kuo
 
PPTX
Learn docker in 90 minutes
Larry Cai
 
KEY
Vagrant
Michael Peacock
 
PDF
Dockerfile
Jeffrey Ellin
 
PPTX
Docker Introductory workshop
Runcy Oommen
 
PPTX
Dockerfile basics | docker workshop #1 at Rackspace
dotCloud
 
PDF
Docker Continuous Delivery Workshop
Jirayut Nimsaeng
 
PDF
Locally it worked! virtualizing docker
Sascha Brinkmann
 
PDF
docker installation and basics
Walid Ashraf
 
PPTX
Installaling Puppet Master and Agent
Ranjit Avasarala
 
PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
PPTX
Vagrant + Docker
David Giordano
 
PDF
Using Docker in the Real World
Tim Haak
 
PDF
Docker 101 - from 0 to Docker in 30 minutes
Luciano Fiandesio
 
PPTX
Docker orchestration
Open Source Consulting
 
PDF
Docker and Puppet — Puppet Camp L.A. — SCALE12X
Jérôme Petazzoni
 
PDF
Docker Presentation at the OpenStack Austin Meetup | 2013-09-12
dotCloud
 
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
dotCloud
 
Docker puebla bday #4 celebration
Ramon Morales
 
Introduction to docker
Wei-Ting Kuo
 
Learn docker in 90 minutes
Larry Cai
 
Dockerfile
Jeffrey Ellin
 
Docker Introductory workshop
Runcy Oommen
 
Dockerfile basics | docker workshop #1 at Rackspace
dotCloud
 
Docker Continuous Delivery Workshop
Jirayut Nimsaeng
 
Locally it worked! virtualizing docker
Sascha Brinkmann
 
docker installation and basics
Walid Ashraf
 
Installaling Puppet Master and Agent
Ranjit Avasarala
 
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
Vagrant + Docker
David Giordano
 
Using Docker in the Real World
Tim Haak
 
Docker 101 - from 0 to Docker in 30 minutes
Luciano Fiandesio
 
Docker orchestration
Open Source Consulting
 
Docker and Puppet — Puppet Camp L.A. — SCALE12X
Jérôme Petazzoni
 
Docker Presentation at the OpenStack Austin Meetup | 2013-09-12
dotCloud
 
Ad

Viewers also liked (9)

PPTX
Docker Overview - AWS Tech Connect - Seattle 10/28
Mike Coleman
 
PPTX
Docker workshop DevOpsDays Amsterdam 2014
Pini Reznik
 
PPTX
Docker & aPaaS: Enterprise Innovation and Trends for 2015
WaveMaker, Inc.
 
PDF
Docker From Scratch
Giacomo Vacca
 
PPTX
Docker networking Tutorial 101
LorisPack Project
 
PDF
Docker in Production
Jirayut Nimsaeng
 
PDF
Docker Workshop for beginner
Jirayut Nimsaeng
 
PDF
Docker Workshop Birthday #3
Jirayut Nimsaeng
 
PPTX
A New Centralized Volume Storage Solution for Docker and Container Cloud by W...
Docker, Inc.
 
Docker Overview - AWS Tech Connect - Seattle 10/28
Mike Coleman
 
Docker workshop DevOpsDays Amsterdam 2014
Pini Reznik
 
Docker & aPaaS: Enterprise Innovation and Trends for 2015
WaveMaker, Inc.
 
Docker From Scratch
Giacomo Vacca
 
Docker networking Tutorial 101
LorisPack Project
 
Docker in Production
Jirayut Nimsaeng
 
Docker Workshop for beginner
Jirayut Nimsaeng
 
Docker Workshop Birthday #3
Jirayut Nimsaeng
 
A New Centralized Volume Storage Solution for Docker and Container Cloud by W...
Docker, Inc.
 
Ad

Similar to Docker workshop (20)

PDF
Introduction to Docker - Learning containerization XP conference 2016
XP Conference India
 
PPTX
Dockerizing a Symfony2 application
Roman Rodomansky
 
PDF
Running the Oracle SOA Suite Environment in a Docker Container
Guido Schmutz
 
PPTX
Running Docker in Development & Production (DevSum 2015)
Ben Hall
 
PDF
Docker for mere mortals
Henryk Konsek
 
PPTX
Real World Experience of Running Docker in Development and Production
Ben Hall
 
PDF
Docker, Kubernetes, and Google Cloud
Samuel Chow
 
PDF
Docker, c'est bonheur !
Alexandre Salomé
 
PDF
手把手帶你學Docker 03042017
Paul Chao
 
PDF
Docker by Example - Basics
Ganesh Samarthyam
 
PDF
JDO 2019: Tips and Tricks from Docker Captain - Łukasz Lach
PROIDEA
 
PDF
Docker 基本概念與指令操作
NUTC, imac
 
PDF
Victor Vieux at Docker Paris Meetup #1
Docker, Inc.
 
PDF
Docker presentation | Paris Docker Meetup
dotCloud
 
PPTX
Docker
Dmitry Bolgarov
 
PDF
時代在變 Docker 要會:台北 Docker 一日入門篇
Philip Zheng
 
PPTX
Running .NET on Docker
Ben Hall
 
PPTX
Introction to docker swarm
Hsi-Kai Wang
 
PPTX
Tribal Nova Docker workshop
Nicolas Degardin
 
PDF
Docker workshop 0507 Taichung
Paul Chao
 
Introduction to Docker - Learning containerization XP conference 2016
XP Conference India
 
Dockerizing a Symfony2 application
Roman Rodomansky
 
Running the Oracle SOA Suite Environment in a Docker Container
Guido Schmutz
 
Running Docker in Development & Production (DevSum 2015)
Ben Hall
 
Docker for mere mortals
Henryk Konsek
 
Real World Experience of Running Docker in Development and Production
Ben Hall
 
Docker, Kubernetes, and Google Cloud
Samuel Chow
 
Docker, c'est bonheur !
Alexandre Salomé
 
手把手帶你學Docker 03042017
Paul Chao
 
Docker by Example - Basics
Ganesh Samarthyam
 
JDO 2019: Tips and Tricks from Docker Captain - Łukasz Lach
PROIDEA
 
Docker 基本概念與指令操作
NUTC, imac
 
Victor Vieux at Docker Paris Meetup #1
Docker, Inc.
 
Docker presentation | Paris Docker Meetup
dotCloud
 
時代在變 Docker 要會:台北 Docker 一日入門篇
Philip Zheng
 
Running .NET on Docker
Ben Hall
 
Introction to docker swarm
Hsi-Kai Wang
 
Tribal Nova Docker workshop
Nicolas Degardin
 
Docker workshop 0507 Taichung
Paul Chao
 

More from Evans Ye (20)

PDF
Join ASF to Unlock Full Possibilities of Your Professional Career.pdf
Evans Ye
 
PDF
非常人走非常路:參與ASF打世界杯比賽
Evans Ye
 
PDF
TensorFlow on Spark: A Deep Dive into Distributed Deep Learning
Evans Ye
 
PDF
2017 big data landscape and cutting edge innovations public
Evans Ye
 
PDF
ONE FOR ALL! Using Apache Calcite to make SQL smart
Evans Ye
 
PDF
The Apache Way: A Proven Way Toward Success
Evans Ye
 
PDF
The Apache Way
Evans Ye
 
PDF
Leveraging docker for hadoop build automation and big data stack provisioning
Evans Ye
 
PDF
Using the SDACK Architecture to Build a Big Data Product
Evans Ye
 
PDF
Trend Micro Big Data Platform and Apache Bigtop
Evans Ye
 
PDF
How bigtop leveraged docker for build automation and one click hadoop provis...
Evans Ye
 
PPTX
How bigtop leveraged docker for build automation and one click hadoop provis...
Evans Ye
 
PPTX
BigTop vm and docker provisioner
Evans Ye
 
PPTX
Fits docker into devops
Evans Ye
 
PPTX
Getting involved in world class software engineering tips and tricks to join ...
Evans Ye
 
PPTX
Deep dive into enterprise data lake through Impala
Evans Ye
 
PPTX
How we lose etu hadoop competition
Evans Ye
 
PPTX
Network Traffic Search using Apache HBase
Evans Ye
 
PPTX
Vagrant
Evans Ye
 
PPTX
Building hadoop based big data environment
Evans Ye
 
Join ASF to Unlock Full Possibilities of Your Professional Career.pdf
Evans Ye
 
非常人走非常路:參與ASF打世界杯比賽
Evans Ye
 
TensorFlow on Spark: A Deep Dive into Distributed Deep Learning
Evans Ye
 
2017 big data landscape and cutting edge innovations public
Evans Ye
 
ONE FOR ALL! Using Apache Calcite to make SQL smart
Evans Ye
 
The Apache Way: A Proven Way Toward Success
Evans Ye
 
The Apache Way
Evans Ye
 
Leveraging docker for hadoop build automation and big data stack provisioning
Evans Ye
 
Using the SDACK Architecture to Build a Big Data Product
Evans Ye
 
Trend Micro Big Data Platform and Apache Bigtop
Evans Ye
 
How bigtop leveraged docker for build automation and one click hadoop provis...
Evans Ye
 
How bigtop leveraged docker for build automation and one click hadoop provis...
Evans Ye
 
BigTop vm and docker provisioner
Evans Ye
 
Fits docker into devops
Evans Ye
 
Getting involved in world class software engineering tips and tricks to join ...
Evans Ye
 
Deep dive into enterprise data lake through Impala
Evans Ye
 
How we lose etu hadoop competition
Evans Ye
 
Network Traffic Search using Apache HBase
Evans Ye
 
Vagrant
Evans Ye
 
Building hadoop based big data environment
Evans Ye
 

Recently uploaded (20)

PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PPTX
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
Activate_Methodology_Summary presentatio
annapureddyn
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 

Docker workshop

  • 2. Agenda • Docker and underlying technologies • Running Docker containers • Building Docker images • The official Docker hub
  • 6. Docker Container • A container is a group of isolated processes – cgroups – namespace • Isolated processes run straight on the host – native CPU performance – minimal memory overhead – minimal network performance overhead
  • 8. Cgroups (control groups) • Linux kernel feature • Groups of processes • Resource limitations – Like limits.conf but the scope is a set of processes instead of uid/gid • May be nested
  • 9. Cgroups submodules • memory • CPU • network IO • disk IO
  • 11. namespaces • Linux kernel feature • wrap particular global system resource in an abstracted, isolated instance • May be nested
  • 12. Different kinds of namespaces
  • 15. Run Docker container in boot2docker directly
  • 16. Create a container with interactive shell $ docker run -t -i base:centos62 /bin/bash [root@4d8c4b81f6d7 /]# exit (exited) $ -t, --tty Allocate a pseudo-TTY $ -i, --interactive Keep STDIN open even if not attached
  • 17. Check containers’ status $ docker ps (only running containers are shown) $ docker ps –a (all)
  • 18. Reattach in stopped container $ docker start -i 4d8c4b81f6d7 [root@4d8c4b81f6d7 /]#
  • 19. or use docker exec instead $ docker start 4d8c4b81f6d7 $ docker exec –ti 4d8c4b81f6d7 bash [root@4d8c4b81f6d7 /]#
  • 20. Take a look at Docker run command $ docker run -t -i base:centos62 /bin/bash
  • 21. Command + args $ docker run base:centos62 /bin/cat /etc/hosts
  • 22. Name a container $ docker run -ti --name foo base:centos62 /bin/bash $ docker ps -a $ docker rm foo destroy foo container
  • 23. Destroy all containers $ docker rm `docker ps --no-trunc -aq` (except running containers, they must be stopped first) $ docker rm -f `docker ps --no-trunc -aq` (force destroy all containers)
  • 24. Create ephemeral container $ docker run -ti --rm base:centos62 /bin/bash [root@4d8c4b81f6d7 /]# exit (destroyed upon exit) $ docker ps -a
  • 25. Ports forwarding (publish) $ docker run -ti -p 80:80 base:centos62 /bin/bash # yum install httpd # echo "hello world" > /var/www/html/index.html # service httpd start $ curl localhost:80
  • 26. What does Docker port forwarding do? Windows / OS X boot2docker Container Container 80 80
  • 27. 27 Well, I need to render it in browsers…
  • 28. How about this? Windows / OS X boot2docker Container Container 80 80 80
  • 29. Doable via Vagrant $ vim Vagrantfile
  • 30. The solution Windows / OS X boot2docker Container Container 80 80 80  Docker port forwarding Vagrant port forwarding
  • 31. More about Docker ports forwarding $ docker run -ti -p 80:80 base:centos62 /bin/bash • -p, --publish Publish a container's port to the host • format: – ip:hostPort:containerPort (10.1.1.1:80:80) – ip::containerPort (10.1.1.1::80) – hostPort:containerPort (80:80)
  • 32. Volume (like sync folder) $ docker run -ti --name apache -v /httpd-logs:/var/log/httpd base:centos62 /bin/bash # touch /var/log/httpd/foo $ ls /http-logs
  • 33. Volume from other container (useful to share data) $ docker run -ti --volumes-from apache base:centos62 /bin/bash # ls /var/log/httpd
  • 34. Link $ docker run -ti --link apache:apache.trendmicro.com base:centos62 /bin/bash # cat /etc/hosts • Exposes information from source container to recipient container in two ways: – Environment variables – Updating the /etc/hosts file • format: – name:alias
  • 35. useful in multi-node situation 12/25/2014 service (hadoop-client) data (hadoop-client) link
  • 36. Docker in client/server mode Windows / OS X boot2docker (Docker client) Linux server Docker Engine Container Container
  • 37. Server: bind Docker engine to a tcp port $ docker -d -H 10.1.1.1:2375 -H unix:///var/run/docker.sock • -d, --daemon daemon mode • -H, --host the socket(s) to bind in daemon mode
  • 38. Docker client $ export DOCKER_HOST=tcp://10.1.1.1:2375 $ docker images $ docker run -ti --rm centos:centos6 /bin/bash (start container on the server) • Note: – expose tcp port could let someone get root access to the host – not recommended in open network
  • 39. Running containers in background (Detached mode) $ hadoop=$(docker run -d -p 50070:50070 tmh6:centos62) $ docker inspect $hadoop
  • 41. Some other VM-like operations $ docker stop $hadoop $ docker start $hadoop $ docker kill $hadoop $ docker rm $hadoop https://docs.docker.com/reference/commandline/cli/
  • 43. 43 There are two ways to build docker images
  • 44. First: commit an existing container • Do changes manually, then commit  quick and dirty  suitable for experiment  might be deleted in the future
  • 45. Second: Build from Dockerfile • Dockerfile is a series of instructions • Use "Docker build" command to build images • pros: – build images automatically by following instructions – visible and easy to understand instructions – enable Docker specific functions in the image – repeatability
  • 46. A sample httpd service Dockerfile FROM base:centos62 COPY index.html /var/www/html/index.html RUN yum -y install httpd EXPOSE 80 CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
  • 47. Build $ mkdir apache-server $ cd apache-server $ echo "our first docker image" > index.html $ vi Dockerfile (paste the sample and save it) $ docker build -t apache:0.1 ./
  • 48. Build context • docker build -t apache:0.1 ./ • ./ will be transferred to Docker daemon as build context • Must have a Dockerfile there – ./Dockerfile • DO NOT build at / – docker build -t apache:0.1 /
  • 49. Run the apache image $ docker run -d --name apache apache:0.1 $ docker run -ti --rm --link apache:a01 base:centos62 /bin/bash # curl $A01_PORT_80_TCP_ADDR (you see how link and expose work together)
  • 50. 50 Use entrypoint to bind a specific executable to the image
  • 51. An httpd service example FROM base:centos62 COPY index.html /var/www/html/index.html RUN yum -y install httpd EXPOSE 80 ENTRYPOINT ["/usr/sbin/httpd"] CMD ["-D", "FOREGROUND"]
  • 52. The difference $ docker run -ti --rm apache:0.1 /bin/bash # (get into the container) $ docker run -ti --rm apache:0.2 /bin/bash show httpd helper message  the only thing you can do is to pass args to httpd
  • 53. Make sure init script always being executed FROM base:centos62 … ENTRYPOINT ["init_wrapper_script"] CMD ["default_args"] https://docs.docker.com/articles/dockerfile_best-practices/
  • 55. Tagging an image $ docker tag -h • dockerhub.evansye.com/base:centos62 – REGISTRYHOST = dockerhub.evansye.com – NAME = base – TAG = centos62
  • 58. Redis $ docker run -d --name some-redis redis $ docker run -ti --rm --link some-redis:redis redis /bin/bash # redis-cli -h $REDIS_PORT_6379_TCP_ADDR -p $REDIS_PORT_6379_TCP_PORT https://registry.hub.docker.com/_/redis/
  • 59. MySQL $ docker run -d --name some-mysql -e MYSQL_ROOT_PASSWORD=demo mysql $ docker run -it --link some-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"' https://registry.hub.docker.com/_/mysql/
  • 60. Jenkins $ docker run -d -p 8080:8080 Jenkins http://HOST_IP:8080 https://registry.hub.docker.com/_/jenkins/
  • 61. Private Docker registry $ docker run -d -p 5000:5000 registry $ docker tag IMAGE HOST_IP:5000/NAME:TAG $ docker push HOST_IP:5000/NAME:TAG https://registry.hub.docker.com/_/registry/
  • 63. Recap docker run • we’ve learned: – port forwarding – volume mounting – linking containers together – running containers at remote
  • 64. Recap docker build • we’ve learned: – how to write a Dockerfile – how expose and link work together – use entrypoint to bind a specific executable with image – ship images to the registry
  • 66. Re-associate Vagrant with VM • VBoxManage list vms • cd .vagrant/machines/docker- platform/virtualbox/ • touch id • echo 33ca… > id

Editor's Notes

  • #30: Check the browser
  • #32: Check the browser
  • #33: Check the browser
  • #34: Check the browser
  • #35: Check the browser
  • #38: Check the browser
  • #39: Check the browser
  • #48: Check the browser
  • #50: Check the browser
  • #53: Check the browser
  • #56: Check the browser
  • #59: Check the browser
  • #60: Check the browser
  • #61: Check the browser
  • #62: Check the browser