Basic usage of Dockerfile
In this article, I will introduce how to build a docker image
Local Folder Preparation
mkdir my_first_image
mkdir docker-web
vi index.html
cd /my_first_image
vi Dockerfile
Dockerfile content
FROM tomcat:latest
MAINTAINER chengze
WORKDIR /usr/local/tomcat/webapps
ADD docker-web ./docker-web
FROM
: specify the basic image for the building image
WORKDIR
: similar to cd command, switch to specified path in container
ADD
: add the folders specified at first parameter into the path in container specified by 2nd parameter.
Generate Image
command: docker build -t mywebapp:1.0 .
docker images
to check generated image
then this image can be executed like a normal image
Case study: Generate a Redis Image
the content of docker file
FROM centos
RUN ["yum", "install", "-y","gcc", "gcc-c++", "net-tools","make"]
WORKDIR /usr/local
ADD <local_redis_tar.gz> .
WORKDIR /usr/local/<redis_folder>/src
RUN make && make install
WORKDIR /usr/local/<redis_folder>
ADD redis.conf .
EXPOSE 7000
CMD ["redis-server", "redis.conf"]