less than 1 minute read

In this article, I will introduce how to build a docker image

Local Folder Preparation

  1. mkdir my_first_image
  2. mkdir docker-web
  3. vi index.html
  4. cd /my_first_image
  5. 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"]