In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you how to build Dockerfile construction image, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Almost all image is generated through Dockerfile. Using Dockerfile allows us to easily build an image. If we need to deploy our own programs, we can often Dockerfile to build the code and environment into an image for use.
1.DockerFile introduction
For projects in hub.docker, authors usually store the Dockerfile corresponding to this image. We can also directly use Dockerfile to generate our own nginx images.
two。 Compile your own nginx
Dockerfile can build an environment based on any image technically. It can be based on an image made by others, such as Nginx, or it can be based on a basic image such as centos. Here, a local nginx:local is built based on a nginx image, and the running image is not used to start nginx, but to output a nginx.
> vim DockerfileFROM nginx:1.13.12CMD ["echo" "nginx"] > docker build-t nginx:local. > docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEnginx local 6ea964efbbc8 10 seconds ago 109 MB > docker Run-it nginx:local > docker run-it nginx:localnginx3.Dockerfile syntax
Various mirrors can be achieved using the following syntax
FROM: specify the parent image. You can create multiple images in the same Dockerfile by adding multiple FROM
MAINTAINER: maintainer information, optional
RUN: the command used to modify the image, which can be used to install the program. When a RUN is completed, a new mirror layer is created on the current image, and the following instructions are executed on the new mirror layer. There are two forms.
RUN ["apt-get", "update"], call exec
RUN apt-get update, called / bin/sh
EXPOSE: used to indicate the port on which the process in the container is open to the public. In docker run, you can add-p (ports not listed in EXPOSE can be set to open to the public) and-P (ports specified in EXPOSE are mapped to other random ports on the host. ) to set the port
ADD: add a file to the new container, which can be
Host file: must be a relative path to the directory where Dockerfile is located (if it is a compressed file, docker will unzip it)
Network file: URL file, which is downloaded and added to the image when the container is created. (if the file is compressed, docker will not extract it.)
Directory: must be a relative path to the directory where Dockerfile is located (if it is a compressed file, docker will unzip it)
COPY: the difference with ADD is that COPY can only be local files, and other uses are the same.
VOLUME: a mount point for the specified path is created in the image. This path can come from the host or other containers. Multiple containers share data through the same mount point. Even if one container has stopped, the other containers can still access the mount point. Only when all container references of the mount point disappear, the mount point will be deleted automatically.
WORKDIR: specify a new working directory for the following instructions. When a container is started, the directory pointed to by the last WORKDIR instruction is the working directory where the container is currently running.
ENV: set the environment variable. You can use-e to set the environment variable docker run-e WEBAPP_PORT=8000-e WEBAPP_HOST=www.example.com when you docker run
CMD: sets the command that the container runs by default. The format of the CMD parameter is similar to RUN. CMD ls-l-an or CMD ["ls", "- l", "- a"]
ENTRYPOIN: similar to CMD, specify the container runtime default command. The difference between ENTRYPOINT and CMD is that when running the container, the command parameters after the image are ENTRYPOINT is stitched and CMD is overridden.
USER: specify a user or UID for the operation of the container and instructions such as RUN CMD ENTRYPOINT
ONBUILD: trigger instruction, which is not executed in the parent image, but only in the child image. Give an example.
So much for sharing on how to build a Dockerfile image. I hope the above content can be of some help to you and learn more. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.