Using Dockerfile to build a nginx container
1. Pull centos mirrors from a remote repository
Docker pull centos
two。 Query image
Docker images
3. Download nginx and pcre to the local directory
4. Edit the Dockerfile file
# Nginx dockerfile
# Version 1.0
# Author: kehaojian
# Base images
FROM centos
# MAINTAINER maintainer
MAINTAINER kehaojian
# ADD add local files to the image
ADD pcre-8.37.tar.gz / usr/local/src
ADD nginx-1.9.3.tar.gz / usr/local/src
# RUN executes commands in the image
RUN yum install-y wget gcc_c++ make openssl-devel
RUN useradd-s / sbin/nologin-M www
# change to directory in WORKDIR image
WORKDIR / usr/local/src/nginx-1.9.3
RUN yum install-y gcc gcc-c++
RUN. / configure-prefix=/usr/local/nginx-- user=www-- group=www-- with-http_ssl_module-- with-http_stub_status_module-- with-pcre=/usr/local/src/pcre-8.37 & & make & & make install
RUN echo "daemon off;" > > / usr/local/nginx/conf/nginx.conf
# configure environment variables
ENV PATH / usr/local/nginx/sbin:$PATH
EXPOSE 80
# Command
CMD ["nginx"]
5. Execute the construction command docker build-t nginx-docker:v1.
[root@HA2 src] # docker build-t nginx-docker:v1.
Sending build context to Docker daemon 8.234 MB
Step 1: FROM centos
-- > 3fa822599e10
Step 2: MAINTAINER kehaojian
-- > Using cache
-- > 7a13a2573c2c
Step 3: ADD pcre-8.37.tar.gz / usr/local/src
-- > Using cache
-- > 27f018c7c6c2
Step 4: ADD nginx-1.9.3.tar.gz / usr/local/src
-- > Using cache
-- > 0ac134999174
Step 5: RUN yum install-y wget gcc_c++ make openssl-devel
-- > Using cache
-- > 2caeaffce308
Step 6: RUN useradd-s / sbin/nologin-M www
-- > Using cache
-> 50fad5 × × × 87
Step 7: WORKDIR / usr/local/src/nginx-1.9.3
-- > Using cache
-- > c223ad0c0e56
Step 8: RUN yum install-y gcc gcc-c++
-- > Using cache
-- > 535006fabee5
Step 9: RUN. / configure-prefix=/usr/local/nginx-user=www-group=www-with-http_ssl_module-with-http_stub_status_module-with-pcre=/usr/local/src/pcre-8.37 & & make & & make install
-- > Using cache
-- > 2c8bfa5d7162
Step 10: RUN echo "daemon off;" > > / usr/local/nginx/conf/nginx.conf
-- > Using cache
-- > 3ab469fa6de1
Step 11: ENV PATH / usr/local/nginx/sbin:$PATH
-- > Using cache
-- > 399e3d091604
Step 12: EXPOSE 80
-- > Using cache
-- > 0e84b1ddfd98
Step 13: CMD nginx
-- > Using cache
-- > 20c4d11561d3
Successfully built 20c4d11561d3
6. View image docker images
7. Launch container docker run-it-d-p 8888 name nginx8888 20c4d11561d3 80-- container
8. View container docker ps-l
9. Visit http://ha2:8888