Writing a Dockerfile
We already know how to get a image and modify it, then share it through Docker Hub. It can be more portable and easy to customize. Just write a script in Dockerfile, and then use docker build
to build an image following the script in Dockerfile!
A demo of a Dockerfile:
FROM tutum/apache-php:latest
MAINTAINER Huang AMing
RUN sed -i 's/archive.ubuntu.com/free.nchc.org.tw/g' \
/etc/apt/sources.list
RUN apt-get update \
&& apt-get install -y php5-xdebug
ADD https://phar.phpunit.de/phpunit.phar /usr/local/bin/
RUN cd /usr/local/bin \
&& chmod +x phpunit.phar \
&& mv phpunit.phar phpunit
FROM: what image would be the base to build
MAINTAINER: declare the maintainer
RUN: to run command in the container in order to build image
ADD: to add file from host OS or remote directory to the specified directory of image, the file would be unziped automatically if it is compressed
Build the image:
docker build <the-Dockerfile-placed>
example> # build image following the Dockerfile in the current directory and tag as ymhuang0808/phpunit-testing:php5.5.9
example> docker build -t="ymhuang0808/phpunit-testing:php5.5.9" .
Flags:
-t
flag assign the new image a tag