Dockerfile

You create a Dockerfile to create an image for your own container. You can specify the base image for your container, commands to execute when setting up the container, ports to expose, files to copy to the container, and the entry point (the program to run when the container starts). Here are some of the frequently used instructions in a Dockerfile:

  • FROM: Specify the base image for your Docker container, for example, FROM Ubuntu.
  • ADD: Add file(s) from the host machine to the Docker container. For example, to copy the setup.sh file from the directory from where Docker commands are run to a container. For example, ADD ./setup.sh /setup.sh.
  • RUN: Runs a command in the container. For example, to make the setup.sh file executable after copying to a container. Example, RUN chmod +x /setup.sh.
  • ENTRYPOINT: Docker containers are meant to have one main application, and when it stops running, the container stops. That main program is specified using the ENTRYPOINT directive. For example, to run the Apache server after it is installed (possibly using the RUN command) ENTRYPOINT apachectl start.
  • CMD: A command to execute. In the absence of ENTRYPOINT, CMD specifies the main application in the container. If specified along with ENTRYPOINT, then the value of CMD is passed as arguments to the application specified in ENTRYPOINT.
  • EXPOSE:  Tells Docker that the container listens on specified port(s) at runtime. For example, if the Apache server is listening on port 80 in a container, then you would specify EXPOSE 80.
  • ENV: Sets environment variable(s) in a container. An example is ENV PATH=/some/path:$PATH.
  • VOLUME: Creates a mountable point for a volume. A volume is just like a folder or virtual folder. From within the container, it can be accessed as any other folder. Volumes can be used to share folders across different running containers. One container can also import volumes from another container.
This is a list of commonly used Docker instructions in a Dockerfile. See the Dockerfile reference at https://docs.docker.com/engine/reference/builder/ for all instructions.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.163.180