Ubuntu 20.04
Sponsored Link

Docker : Use Dockerfile
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management.
[1] For example, Create a Dockerfile that Nginx is installed and started.
vi Dockerfile
# create new

FROM ubuntu
MAINTAINER ServerWorld <admin@srv.world>

RUN apt-get update
RUN apt-get -y install nginx
RUN echo "Dockerfile Test on Nginx" > /var/www/html/index.html

CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

# build image ⇒ docker build -t [image name]:[tag] .

docker build -t nginx_server:latest ./

Sending build context to Docker daemon   25.6kB
Step 1/7 : FROM ubuntu
 ---> 1d622ef86b13
Step 2/7 : MAINTAINER ServerWorld <admin@srv.world>
 ---> Using cache
 ---> f0e63877306b
Step 3/7 : RUN apt update
 ---> Running in bcd6fcaa6ded
Successfully built 2d5672bca343
Successfully tagged nginx_server:latest

docker images

REPOSITORY               TAG                 IMAGE ID            CREATED              SIZE
nginx_server             latest              2d5672bca343        About a minute ago   155MB
srv.world/ubuntu_nginx   latest              d30733d4f315        About an hour ago    155MB
ubuntu                   latest              1d622ef86b13        5 weeks ago          73.9MB

# run container

docker run -d -p 8081:80 nginx_server

docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
b030bf10dab3        nginx_server        "/usr/sbin/nginx -g …"   9 seconds ago       Up 8 seconds>80/tcp   cranky_kilby

# verify accesses

curl localhost:8081

Dockerfile Test on Nginx
The format of Dockerfile is [INSTRUCTION arguments] .
Refer to the following description for INSTRUCTION.
FROM iIt sets the Base Image for subsequent instructions.
MAINTAINER It sets the Author field of the generated images.
RUN It will execute any commands when Docker image will be created.
CMD It will execute any commands when Docker container will be executed.
ENTRYPOINT It will execute any commands when Docker container will be executed.
LABEL It adds metadata to an image.
EXPOSE It informs Docker that the container will listen on the specified network ports at runtime.
ENV It sets the environment variable.
ADD It copies new files, directories or remote file URLs.
COPY It copies new files or directories.
The differences of [ADD] are that it's impossible to specify remore URL and also it will not extract archive files automatically.
VOLUME It creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers
USER It sets the user name or UID.
WORKDIR It sets the working directory.

Matched Content