A usage instance of Docker Dockerfile
- 2020-05-24 06:30:09
- OfStack
Dockerfile
FROM base mirror
MAINTAINER maintains this information
What command does RUN run, preceded by RUN
ADD add some files to it, copy files, it will unzip automatically
WORKDIR current working directory
Mount the VOLUME directory
EXPOSE open port
The RUN process runs 1 straight
Actual combat: build nginx
wget http://xiazai.ofstack.com/201611/yuanma/nginx-1.9.3(ofstack.com).rar
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
#This is My first Dockerfile#version 1.0
#Author: hh
#Base image Base image
FROM centos
#MAINTAINER Maintainer information
MAINTAINER hh Wang
#ADD
ADD pcre-8.38.tar.gz /usr/local/srcADD nginx-1.9.3.tar.gz /usr/local/src
#RUN
RUN yum -y install wget gcc gcc-c++ make openssl openssl-devel
RUN useradd -s /sbin/nologin -M www
#WORKDIR
WORKDIR /usr/local/src/nginx-1.9.3
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.38 && make && make install
RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf
#ENV Define environment variables
ENV PATH /usr/local/nginx/sbin:$PATH
#EXPOSE Port mapping
EXPOSE 80 CMD ["nginx"]
docker build -t whh/nginx-file:v1 .
docker run -d -it -p 93:80 --name nginx whh/nginx-file:v1
Now let's look at the use of dockerfile
Mirroring can be done with the docker build command.
Usually a text file Dockerfile is required, as shown below:
from hub. c. 163. com/library nginx - based on the image
run echo "hello world" > / etc nginx/index xml -- appended to index. html at the end
expose 80 -- exposed port 80
cmd 'nginx' -- start the nginx service
After saving, run docker build-t mynginx:1.0.
Then run docker images and see the image you built.
docker run-d-p 8082:80 --name nginx_web mynginx:1.0
Finally, http://ip:8081 is accessed via http://ip:8081 to nginx's index.html