SlideShare a Scribd company logo
Dockerfile Basics
Docker workshop #2 at @Twitter, beginners class
#dockerworkshop
By Julien Barbier @julienbarbier42
@
Docker version 0.6.5
Dockerfiles
• Dockerfiles = image representations
• Simple syntax for building images
• Automate and script the images creation
42h
FROM
• Sets the base image for subsequent instructions
• Usage: FROM <image>
• Example: FROM ubuntu
• Needs to be the first instruction of every Dockerfile
• TIP: find images with the command: docker search
42h
RUN
• Executes any commands on the current image and commit the
results
• Usage: RUN <command>
• Example: RUN apt-get install –y memcached
FROM ubuntu
RUN apt-get install -y memcached
is equivalent to:
$ docker run ubuntu apt-get install -y memcached
$ docker commit XXX
42h
docker build
Creates an image from a Dockerfile
• From the current directory
• From stdin
• From GitHub
TIP: Use –t to tag your image
$ docker build github.com/creack/docker-firefox
$ docker build - < Dockerfile
$ docker build .
42h
Example: Memcached
FROM ubuntu
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main
universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y memcached
• Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-
Twitter/blob/master/slide_6/Dockerfile
• Test it
$ docker run -i -t memcached_d1 /bin/bash
root@1f452c9442fb:/# memcached -u daemon -vvv
$ docker build –t memcached_d1 .
42h
#Commenting
• #
• Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-
Twitter/blob/master/slide_7/Dockerfile
# Memcached
#
# VERSION 1.0
# use the ubuntu base image provided by Docker
FROM ubuntu
# make sure the package repository is up to date
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" >
/etc/apt/sources.list
RUN apt-get update
# install memcached
RUN apt-get install -y memcached
42h
MAINTAINER
• specify name / contact of the person maintaining the Dockerfile
• Example: MAINTAINER Julien, julien@docker.com
• Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-
Twitter/blob/master/slide_8/Dockerfile
# Memcached
#
# VERSION 1.0
# use the ubuntu base image provided by Docker
FROM ubuntu
MAINTAINER Julien, julien@docker.com
# make sure the package repository is up to date
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
# install memcached
RUN apt-get install -y memcached
42h
ENTRYPOINT 1/2
• Triggers a command as soon as the container starts
• Example: ENTRYPOINT echo “Whale You Be My Container?”
• Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/slide_9/Dockerfile
# Whale you be my container?
#
# VERSION 0.42
# use the base image provided by Docker
FROM base
MAINTAINER Moby Dock victor.coisne@docker.com
# say hello when the container is launched
ENTRYPOINT echo "Whale you be my container"
42h
ENTRYPOINT 2/2
• Run containers as executables! :)
• Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-
Twitter/blob/master/slide_10/Dockerfile
# This is wc
#
# VERSION 0.42
# use the base image provided by Docker
FROM base
MAINTAINER Roberto roberto@docker.com
# count lines with wc
ENTRYPOINT ["wc", "-l"]
42h
$ cat /etc/passwd | docker run -i wc
USER
• Sets the username to use when running the image
• Example: USER daemon
42h
EXPOSE
• Sets ports to be exposed to other containers when running the
image (cf lightning talk by Michael Crosby @crosbymichael)
• Example: EXPOSE 80
42h
Exercice: create a perfect Memcached
Dockerfile
Answer https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/memcached/Dockerfile
#BOOM
• Try it (update port number, $ docker ps)
Python https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/memcached/test.py
Ruby https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/memcached/test.rb
PHP https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/memcached/test.php
42h
$ docker build -t memcached .
$ docker run –p 11211 memcached
Quizz: Online Dockerfile Tutorials
Test your skills here:
http://www.docker.io/learn/dockerfi
le/
42h
www.docker.io
Thank you!
42h

More Related Content

What's hot (19)

PDF
OpenStack - Docker - Rackspace HQ
dotCloud
 
PDF
Introduction to docker
Wei-Ting Kuo
 
PDF
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
dotCloud
 
PDF
Dockerizing your applications - Docker workshop @Twitter
dotCloud
 
PDF
Intro To Docker
Jessica Lucci
 
PPTX
Docker
Hussien Elhannan
 
PPTX
What is Docker
Pavel Klimiankou
 
PDF
Docker Continuous Delivery Workshop
Jirayut Nimsaeng
 
PDF
Docker by Example - Basics
Ganesh Samarthyam
 
PDF
Introduction to docker
Walid Ashraf
 
PDF
Docker 101: An Introduction
POSSCON
 
PDF
Vagrant + Docker provider [+Puppet]
Nicolas Poggi
 
PDF
Automating Docker Containers with Puppet 2014 10-13
kylog
 
PDF
docker installation and basics
Walid Ashraf
 
PDF
Vagrant and docker
DuckDuckGo
 
ODP
Ruby and Docker on Rails
Muriel Salvan
 
PDF
Locally it worked! virtualizing docker
Sascha Brinkmann
 
PDF
Introduction To Docker
Hamilton Turner
 
PPTX
Austin - Container Days - Docker 101
Bill Maxwell
 
OpenStack - Docker - Rackspace HQ
dotCloud
 
Introduction to docker
Wei-Ting Kuo
 
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
dotCloud
 
Dockerizing your applications - Docker workshop @Twitter
dotCloud
 
Intro To Docker
Jessica Lucci
 
What is Docker
Pavel Klimiankou
 
Docker Continuous Delivery Workshop
Jirayut Nimsaeng
 
Docker by Example - Basics
Ganesh Samarthyam
 
Introduction to docker
Walid Ashraf
 
Docker 101: An Introduction
POSSCON
 
Vagrant + Docker provider [+Puppet]
Nicolas Poggi
 
Automating Docker Containers with Puppet 2014 10-13
kylog
 
docker installation and basics
Walid Ashraf
 
Vagrant and docker
DuckDuckGo
 
Ruby and Docker on Rails
Muriel Salvan
 
Locally it worked! virtualizing docker
Sascha Brinkmann
 
Introduction To Docker
Hamilton Turner
 
Austin - Container Days - Docker 101
Bill Maxwell
 

Similar to Dockerfile Basics Workshop #2 (20)

PPTX
Dockerfile at Guidewire
Docker, Inc.
 
PPTX
Dockerfile Basics Workshop #1
Docker, Inc.
 
PDF
Docker presentation | Paris Docker Meetup
dotCloud
 
PDF
Victor Vieux at Docker Paris Meetup #1
Docker, Inc.
 
PPSX
Docker and containers - Presentation Slides by Priyadarshini Anand
PRIYADARSHINI ANAND
 
PDF
手把手帶你學Docker 03042017
Paul Chao
 
PDF
Docker use dockerfile
cawamata
 
PDF
Computer science docker file Week -6 to7
jemy24r
 
PDF
Docker workshop 0507 Taichung
Paul Chao
 
PDF
手把手帶你學 Docker 入門篇
Philip Zheng
 
PDF
The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
Docker, Inc.
 
PPTX
Docker Workshop
Ahmad Rafiee
 
PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
PDF
Docker & FieldAware
Jakub Jarosz
 
PDF
Docker Demo @ IuK Seminar
Martin Scharm
 
PPTX
Docker advance topic
Kalkey
 
PDF
Introduction to Docker - Learning containerization XP conference 2016
XP Conference India
 
PPTX
Docker advance1
Gourav Varma
 
PDF
Getting Started with Docker
Anup Segu
 
PDF
How to write a Dockerfile
Knoldus Inc.
 
Dockerfile at Guidewire
Docker, Inc.
 
Dockerfile Basics Workshop #1
Docker, Inc.
 
Docker presentation | Paris Docker Meetup
dotCloud
 
Victor Vieux at Docker Paris Meetup #1
Docker, Inc.
 
Docker and containers - Presentation Slides by Priyadarshini Anand
PRIYADARSHINI ANAND
 
手把手帶你學Docker 03042017
Paul Chao
 
Docker use dockerfile
cawamata
 
Computer science docker file Week -6 to7
jemy24r
 
Docker workshop 0507 Taichung
Paul Chao
 
手把手帶你學 Docker 入門篇
Philip Zheng
 
The Dockerfile Explosion and the Need for Higher Level Tools by Gareth Rushgrove
Docker, Inc.
 
Docker Workshop
Ahmad Rafiee
 
Primi passi con Docker - ItalianCoders - 12-01-2021
Alessandro Mignogna
 
Docker & FieldAware
Jakub Jarosz
 
Docker Demo @ IuK Seminar
Martin Scharm
 
Docker advance topic
Kalkey
 
Introduction to Docker - Learning containerization XP conference 2016
XP Conference India
 
Docker advance1
Gourav Varma
 
Getting Started with Docker
Anup Segu
 
How to write a Dockerfile
Knoldus Inc.
 
Ad

More from Docker, Inc. (20)

PDF
Containerize Your Game Server for the Best Multiplayer Experience
Docker, Inc.
 
PDF
How to Improve Your Image Builds Using Advance Docker Build
Docker, Inc.
 
PDF
Build & Deploy Multi-Container Applications to AWS
Docker, Inc.
 
PDF
Securing Your Containerized Applications with NGINX
Docker, Inc.
 
PDF
How To Build and Run Node Apps with Docker and Compose
Docker, Inc.
 
PDF
Hands-on Helm
Docker, Inc.
 
PDF
Distributed Deep Learning with Docker at Salesforce
Docker, Inc.
 
PDF
The First 10M Pulls: Building The Official Curl Image for Docker Hub
Docker, Inc.
 
PDF
Monitoring in a Microservices World
Docker, Inc.
 
PDF
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
Docker, Inc.
 
PDF
Predicting Space Weather with Docker
Docker, Inc.
 
PDF
Become a Docker Power User With Microsoft Visual Studio Code
Docker, Inc.
 
PDF
How to Use Mirroring and Caching to Optimize your Container Registry
Docker, Inc.
 
PDF
Monolithic to Microservices + Docker = SDLC on Steroids!
Docker, Inc.
 
PDF
Kubernetes at Datadog Scale
Docker, Inc.
 
PDF
Labels, Labels, Labels
Docker, Inc.
 
PDF
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Docker, Inc.
 
PDF
Build & Deploy Multi-Container Applications to AWS
Docker, Inc.
 
PDF
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
Docker, Inc.
 
PDF
Developing with Docker for the Arm Architecture
Docker, Inc.
 
Containerize Your Game Server for the Best Multiplayer Experience
Docker, Inc.
 
How to Improve Your Image Builds Using Advance Docker Build
Docker, Inc.
 
Build & Deploy Multi-Container Applications to AWS
Docker, Inc.
 
Securing Your Containerized Applications with NGINX
Docker, Inc.
 
How To Build and Run Node Apps with Docker and Compose
Docker, Inc.
 
Hands-on Helm
Docker, Inc.
 
Distributed Deep Learning with Docker at Salesforce
Docker, Inc.
 
The First 10M Pulls: Building The Official Curl Image for Docker Hub
Docker, Inc.
 
Monitoring in a Microservices World
Docker, Inc.
 
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
Docker, Inc.
 
Predicting Space Weather with Docker
Docker, Inc.
 
Become a Docker Power User With Microsoft Visual Studio Code
Docker, Inc.
 
How to Use Mirroring and Caching to Optimize your Container Registry
Docker, Inc.
 
Monolithic to Microservices + Docker = SDLC on Steroids!
Docker, Inc.
 
Kubernetes at Datadog Scale
Docker, Inc.
 
Labels, Labels, Labels
Docker, Inc.
 
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Docker, Inc.
 
Build & Deploy Multi-Container Applications to AWS
Docker, Inc.
 
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
Docker, Inc.
 
Developing with Docker for the Arm Architecture
Docker, Inc.
 
Ad

Dockerfile Basics Workshop #2

  • 1. Dockerfile Basics Docker workshop #2 at @Twitter, beginners class #dockerworkshop By Julien Barbier @julienbarbier42 @ Docker version 0.6.5
  • 2. Dockerfiles • Dockerfiles = image representations • Simple syntax for building images • Automate and script the images creation 42h
  • 3. FROM • Sets the base image for subsequent instructions • Usage: FROM <image> • Example: FROM ubuntu • Needs to be the first instruction of every Dockerfile • TIP: find images with the command: docker search 42h
  • 4. RUN • Executes any commands on the current image and commit the results • Usage: RUN <command> • Example: RUN apt-get install –y memcached FROM ubuntu RUN apt-get install -y memcached is equivalent to: $ docker run ubuntu apt-get install -y memcached $ docker commit XXX 42h
  • 5. docker build Creates an image from a Dockerfile • From the current directory • From stdin • From GitHub TIP: Use –t to tag your image $ docker build github.com/creack/docker-firefox $ docker build - < Dockerfile $ docker build . 42h
  • 6. Example: Memcached FROM ubuntu RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list RUN apt-get update RUN apt-get install -y memcached • Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2- Twitter/blob/master/slide_6/Dockerfile • Test it $ docker run -i -t memcached_d1 /bin/bash root@1f452c9442fb:/# memcached -u daemon -vvv $ docker build –t memcached_d1 . 42h
  • 7. #Commenting • # • Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2- Twitter/blob/master/slide_7/Dockerfile # Memcached # # VERSION 1.0 # use the ubuntu base image provided by Docker FROM ubuntu # make sure the package repository is up to date RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list RUN apt-get update # install memcached RUN apt-get install -y memcached 42h
  • 8. MAINTAINER • specify name / contact of the person maintaining the Dockerfile • Example: MAINTAINER Julien, [email protected] • Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2- Twitter/blob/master/slide_8/Dockerfile # Memcached # # VERSION 1.0 # use the ubuntu base image provided by Docker FROM ubuntu MAINTAINER Julien, [email protected] # make sure the package repository is up to date RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list RUN apt-get update # install memcached RUN apt-get install -y memcached 42h
  • 9. ENTRYPOINT 1/2 • Triggers a command as soon as the container starts • Example: ENTRYPOINT echo “Whale You Be My Container?” • Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/slide_9/Dockerfile # Whale you be my container? # # VERSION 0.42 # use the base image provided by Docker FROM base MAINTAINER Moby Dock [email protected] # say hello when the container is launched ENTRYPOINT echo "Whale you be my container" 42h
  • 10. ENTRYPOINT 2/2 • Run containers as executables! :) • Dockerfile: https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2- Twitter/blob/master/slide_10/Dockerfile # This is wc # # VERSION 0.42 # use the base image provided by Docker FROM base MAINTAINER Roberto [email protected] # count lines with wc ENTRYPOINT ["wc", "-l"] 42h $ cat /etc/passwd | docker run -i wc
  • 11. USER • Sets the username to use when running the image • Example: USER daemon 42h
  • 12. EXPOSE • Sets ports to be exposed to other containers when running the image (cf lightning talk by Michael Crosby @crosbymichael) • Example: EXPOSE 80 42h
  • 13. Exercice: create a perfect Memcached Dockerfile Answer https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/memcached/Dockerfile #BOOM • Try it (update port number, $ docker ps) Python https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/memcached/test.py Ruby https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/memcached/test.rb PHP https://github.com/jbarbier/Dockerfile-Basics-Docker-Workshop-2-Twitter/blob/master/memcached/test.php 42h $ docker build -t memcached . $ docker run –p 11211 memcached
  • 14. Quizz: Online Dockerfile Tutorials Test your skills here: http://www.docker.io/learn/dockerfi le/ 42h