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
Of Dockerfile:

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 :
<html>
  <head><title>hello</title></header>
  <body>I have changed the nginx page.</body>
</html>

to write Dockerfile:
#  from  nginx  Mirror start writing
FROM nginx:latest

#  Specify the default working directory for the container
WORKDIR /usr/share/nginx/html

#  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

FROM

Must write , Indicates which base image to build from .
FROM untuntu
#  from  0  start
FROM scratch

WORKDIR

working directory
WORKDIR /usr/share
#  Equivalent to operation  cd /usr/share

COPY / ADD

Add local file . General use COPY
COPY localfile /dest/file

ENV

Add environment variable .
ENV <key> <value> ENV <key>=<value> ...
EXPOSE

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 .

VOLUME

Data volume .

RUN

Instructions to run , It could be shell format , Or it could be exec format .
RUN yum install wget
RUN ["yum", "install", "wget"]

CMD

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

Technology
©2019-2020 Toolsou All rights reserved,
c Language to achieve mine clearance Games and mine source code Node.js Middle template engine 3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! The situation of receiving and receiving multi-path git It's set correctly ssh, But it still prompts Permission denied (publickey) new iPhone I won't support it 5G Will lead to further decline in shipment C# Sorting method of Chinese Dictionaries 10909 rice ! Chinese fighter successfully landed in Mariana Trench MySQL8.0MGR Single owner / Multi master installation and switching Java Poor reflection performance ?