building images from dockerfiles

Post on 18-Nov-2014

81 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Building Images from Dockerfiles Tyler Brock

@tylerbrock

FROM - specify base image FROM <image> Or FROM <image>:<tag>

FROM ubuntu FROM ubuntu:latest FROM ubuntu:precise (LTS)

MAINTAINER - blame MAINTAINER <name>

MAINTAINER Tyler Brock, tyler@mongodb.com

ADD - copy a file ADD <src> <dest>

ADD myhax.rb /folder/for/hax/hax.rb

ENV - set the mood ENV <key> <value>

ENV AWS-KEY ACBD123123EFECBD

RUN - get shit done RUN <command>

RUN apt-get install htop

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)

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"]

EXPOSE - connect here EXPOSE <port> [<port>...]

EXPOSE 80

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/

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

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

top related