Learning - Dockerfile
This is to refresh my Dockerfile knowledge.
alphine
Create Dockerfile
FROM alphine:3.4
MAINTAINER Mark Takacs mark@takacsmark.com
RUN ark update
RUN ark add vim
RUN apk add curl
Build
docker build -t taka/alpine-smarter:1.0 .
Intermediate images
The Docker intermediate images can speed up the rebuilding process.
docker images -a
To reduce number of intermediate images, update Dockerfile as below
FROM alphine:3.4
MAINTAINER Mark Takacs mark@takacsmark.com
RUN ark update && \
ark add vim && \
apk add curl
Clean up dangling image
docker images --filter "dangling=true"
docker rmi $(docker images -q --filter "dangling=true")
python
Dockerfile
- For normal python
FROM python:3.6.1
RUN pip install numpy
- For alpine version takes much longer time to build
FROM python:3.6.1-alpine
RUN apk update && apk add build-base
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h
RUN pip install numpy scipy
conda3
- miniconda3
docker run --rm -ti continuumio/miniconda3 /bin/bash
conda list
conda install numpy
- anaconda3
docker run --rm -ti continuumio/anaconda3 /bin/bash
conda list
phpslim
Dockerfile
Choose php:7.1.2-apache
Got to https://getcomposer.org, and run installation commands in container
FROM php:7.1.2-apache
RUN ....
COPY ./composer.json /var/www/html/
RUN apt-get update & apt-get install -y git
RUN composer install
Map directory
To run docker container with option -v /var/www/html/vendor
to indicate using image /var/www/html/vendor
folder.
docker run --rm -v $(pwd):/var/www/html/ -v /var/www/html/vendor -p 80:80 takacsmark/phpslim-tut:1.0
As the result, the /var/www/html
is mapped to local directory, but /var/www/html/vendor
is image directory.
Change DocumentRoot
Add following line into Dockerfile to change the DocumentRoot
to /var/www/html/public
RUN set -i 's/DocumentRoot.*$/DocumentRoot \/var\/www\/html\/public/' /etc/apache2/sites-enabled/000-default.conf
Enable default hello message
Create a file /var/www/html/public/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Run following command in container to enable module rewrite
a2enmod rewrite
Then add following line in Dockerfile
RUN a2enmod rewrite
Options
COPY
COPY ./config.txt /usr/src/config.txt
ADD
-
Add URL file from internet
-
Add tar file
-
Add compressed file
RUN
EXPOSE
Port
USER
WORKDIR
ARG
LABEL
ENTRYPOINT & CMD
To run command echo Welcome
after container created, following configuration can be used.
CMD "Welcome"
ENTRYPOINT echo
The CMD
option can be replace using docker run command line, ENTRYPOINT
can't. For example, following command will run echo Hello
.
docker run echo_image 'Hello'
ENV
References
Dockerfile Tutorial by Example - ( Part I - Basics )
Dockerfile Tutorial by Example - ( Part II - Best practices )
Dockerfile Tutorial by Example - ( Part III - Creating a docker PHP Slim image )