dockerfile basics | docker workshop #1 at rackspace

16
Dockerfile basics docker workshop #1 at GeekDom / Rackspace

Upload: dotcloud

Post on 28-Jan-2015

111 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Dockerfile basics | docker workshop #1 at Rackspace

Dockerfile basicsdocker workshop #1

at GeekDom / Rackspace

Page 2: Dockerfile basics | docker workshop #1 at Rackspace

Dockerfiles

• Dockerfiles = image representations• Simple syntax for building images• Automate and script the images creation

Page 3: Dockerfile basics | docker workshop #1 at Rackspace

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

Page 4: Dockerfile basics | docker workshop #1 at Rackspace

RUN

• Executes any commands on the current image and commit the results• Usage: RUN <command>• Example: RUN apt-get install –y memcached

FROM ubuntuRUN apt-get install -y memcached• Is equivalent to:docker run ubuntu apt-get install -y memcacheddocker commit XXX

Page 5: Dockerfile basics | docker workshop #1 at Rackspace

docker build

• Creates an image from a Dockerfile• From the current directory = docker build• From stdin = docker build - < Dockerfile• From GitHub = docker build github.com/creack/docker-firefox

• TIP: Use –t to tag your image

Page 6: Dockerfile basics | docker workshop #1 at Rackspace

Example: Memcached

FROM ubuntuRUN echo "deb http://archive.ubuntu.com/ubuntu precise

main universe" > /etc/apt/sources.listRUN apt-get updateRUN apt-get install -y memcached• http://instacached.com/D1• Docker build –t memcached .

Page 7: Dockerfile basics | docker workshop #1 at Rackspace

# Commenting

• #• http://instacached.com/D2

# Memcached## VERSION 1.0

# use the ubuntu base image provided by dotCloudFROM ubuntu

# make sure the package repository is up to dateRUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" >

/etc/apt/sources.listRUN apt-get update

# install memcachedRUN apt-get install -y memcached

Page 8: Dockerfile basics | docker workshop #1 at Rackspace

MAINTAINER

• specify name / contact of the person maintaining the Dockerfile• Example: MAINTAINER Yannis, [email protected]• http://instacached.com/D3

# Memcached## VERSION 1.0

# use the ubuntu base image provided by dotCloudFROM ubuntu

MAINTAINER Yannis, [email protected]

# make sure the package repository is up to dateRUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.listRUN apt-get update

# install memcachedRUN apt-get install -y memcached

Page 9: Dockerfile basics | docker workshop #1 at Rackspace

ENTRYPOINT 1/2

• Triggers a command as soon as the container starts• Example: ENTRYPOINT echo “Whale You Be My Container?”• http://instacached.com/D4

# Whale you be my container?## VERSION 0.42

# use the base image provided by dotCloudFROM base

MAINTAINER Victor Coisne [email protected]

# say hello when the container is launchedENTRYPOINT echo "Whale you be my container"

Page 10: Dockerfile basics | docker workshop #1 at Rackspace

ENTRYPOINT 2/2

• Run containers as executables! :)• cat /etc/passwd | docker run -i wc• http://instacached.com/D5

# This is wc # # VERSION 0.42

# use the base image provided by dotCloud FROM base

MAINTAINER Victor Coisne [email protected]

# count lines with wc ENTRYPOINT ["wc", "-l"]

Page 11: Dockerfile basics | docker workshop #1 at Rackspace

USER

• Sets the username to use when running the image• Example: USER daemon

Page 12: Dockerfile basics | docker workshop #1 at Rackspace

EXPOSE

• Sets ports to be publicly exposed when running the image• Example: EXPOSE 11211

Page 13: Dockerfile basics | docker workshop #1 at Rackspace

Memcached

• http://instacached.com/Dockerfile• docker build -t memcached - < Dockerfile• docker run memcached

• BOOM! :)

• Try it• Python: http://instacached.com/test.py.txt• Ruby: http://instacached.com/test.rb.txt• PHP: http://instacached.com/test.php.txt

Page 14: Dockerfile basics | docker workshop #1 at Rackspace

Online Dockerfile Tutorials

• Check our Dockerfile tutorials and test your skills here:

http://www.docker.io/learn/dockerfile/

Page 15: Dockerfile basics | docker workshop #1 at Rackspace

Thank you

• GeekDom SF• Rackspace• Docker / dotCloud

• Blake Haggerty• Robert Hrdinsky

• You!

Page 16: Dockerfile basics | docker workshop #1 at Rackspace

www.docker.io