Building images from dockerfiles

8,366 views

Published on

Tyler Brock explains how he build images from dockerfiles

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,366
On SlideShare
0
From Embeds
0
Number of Embeds
504
Actions
Shares
0
Downloads
50
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Building images from dockerfiles

  1. 1. Building Images from Dockerfiles Tyler Brock @tylerbrock
  2. 2. FROM - specify base image FROM <image> Or FROM <image>:<tag> FROM ubuntu FROM ubuntu:latest FROM ubuntu:precise (LTS)
  3. 3. MAINTAINER - blame MAINTAINER <name> MAINTAINER Tyler Brock, tyler@mongodb.com
  4. 4. ADD - copy a file ADD <src> <dest> ADD myhax.rb /folder/for/hax/hax.rb
  5. 5. ENV - set the mood ENV <key> <value> ENV AWS-KEY ACBD123123EFECBD
  6. 6. RUN - get shit done RUN <command> RUN apt-get install htop
  7. 7. CMD - what should it do? ●  CMD ["executable","param1","param2"] (like an exec, preferred form) ●  CMD ["param1","param2"] (as default parameters to ENTRYPOINT) ●  CMD command param1 param2 (as a shell)
  8. 8. ENTRYPOINT - start here ENTRYPOINT ["executable", "param1", "param2"] (like an exec, preferred form) ENTRYPOINT command param1 param2 (as a shell) ENTRYPOINT wc -l - CMD ["-l", "-"] ENTRYPOINT ["/usr/bin/wc"]
  9. 9. EXPOSE - connect here EXPOSE <port> [<port>...] EXPOSE 80
  10. 10. VOLUME VOLUME ["/data"] The VOLUME instruction will add one or more new volumes to any container created from the image. Puts /data here: /var/lib/docker/volumes/
  11. 11. Dockerfile - the main event # What image are we using? FROM ubuntu # Take some credit MAINTAINER Tyler Brock, tyler@mongodb.com # Add 10gen official apt source to the sources list RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list # Hack for initctl not being available in Ubuntu RUN dpkg-divert --local --rename --add /sbin/initctl RUN ln -s /bin/true /sbin/initctl # Install MongoDB RUN apt-get update RUN apt-get install mongodb-10gen # Install a sensible config ADD mongod.conf /etc/mongod.conf # Setup the image as an executable that runs MongoDB CMD ["--config", "/etc/mongod.conf"] ENTRYPOINT ["/usr/bin/mongod"] EXPOSE 27017
  12. 12. Build, Run, Enjoy docker build -t <repo/image name> /path/to/dockerfiledir docker build -t tbrock/mongodb . docker -d -v <host>:<container> <image/tag> docker run -d -v /home/ubuntu/data: /data tbrock/mongodb

×