primary coverage ：
* What is? Dockerfile
* see DockerHub Mirrored in Dockerfile
* Dockerfile to write
* Dockerfile Common commands
What is? Dockerfile
use Docker It is often necessary to customize new images based on existing images ,Dockerfile This process of image customization can be saved . Well written Dockerfile
after , You can reuse this file to build the same image on different machines .
see DockerHub Mirrored in Dockerfile
You can DockerHub Click the label on any image page in , see Dockerfile file , For example, click nginx Of latest label , notice nginx
Dockerfile to write
next , I can be in the official nginx Customization based on image . default nginx Page opening is like this ：
The effect I want to achieve is page display ：
I have changed the nginx page.
First, prepare the replacement index.html page ：
<body>I have changed the nginx page.</body>
to write Dockerfile：
# from nginx Mirror start writing
# Specify the default working directory for the container
# Copy local files to docker in
COPY index.html index.html
stay index.html and Dockerfile Peer directory execute build instruction ：
docker image build -t nginx_custom:latest .
next , adopt nginx_custom The name tag runs the container , visit 8000 Port can see the effect after customization .
docker container run -p 8000:80 nginx_custom:latest
Dockerfile Common commands
Must write , Indicates which base image to build from .
# from 0 start
# Equivalent to operation cd /usr/share
COPY / ADD
Add local file . General use COPY
COPY localfile /dest/file
Add environment variable .
ENV <key> <value> ENV <key>=<value> ...
Open port . Ports that the container can listen to . EXPOSE 80/udp , Agreement can be left blank . Note and run the program's -p distinguish .
Data volume .
Instructions to run , It could be shell format , Or it could be exec format .
RUN yum install wget
RUN ["yum", "install", "wget"]
One Dockerfile Only once in , Command to run when container is open . Like starting a python program ： python run.py. Format also supports shell and
exec format .
CMD python run.py