Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build an image using docker file

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to build an image using docker file. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Getting started with Docker File (1) requirements

To get started with building an image using docker file, let's start with a simple requirement:

Use docker file to make a simple tomcat image so that the running image displays a custom home page.

Process 1. Learn about tomcat mirroring

To build such an image, we must first connect to the directory structure of the original tomcat image:

Use the command docker run-it tomcat bash to open a shell with an interactive terminal

In the end, we just want to add a HTML to the / usr/local/tomcat/webapps/ROOT directory.

two。 Build an image

Change to the / usr/local directory and create a docker/tomcat folder under the directory.

1) create a text file and name it Dockerfile:

FROM tomcatWORKDIR / usr/local/tomcat/webapps/ROOT/RUN rm-rf * RUN echo "Hello Docker" > / usr/local/tomcat/webapps/ROOT/index.html

FROM means to build on tomcat, similar to inheritance in JAVA, then change the working directory to Root, delete all files in this directory, and add Hello Docker to index.html.

2) build an image

Run the command docker build-t mytomcat.

At this point, a self-image is built. Check the image:

Run and build your own tomcat image: docker run-p-- rm 8080 mytomcat

The result is shown in the figure:

Description:

About docker build-t mytomcat. Many people will think that this in the command is to specify the file location of the docker file, but this view is not accurate. Refers to the context path of.

As we all know, docker is a CS architecture software, which can also be seen through docker version:

The Docker engine provides a set of REST API, and the commands we enter interact with the Docker engine through this set of API to complete various functions. So although on the surface we seem to be performing various docker functions natively, in fact, everything is done on the server side (the Docker engine) in the form of remote invocations.

When building, the user will specify the path to build the image context. When the docker build command knows this path, it will package all the contents under the path and upload it to the Docker engine. So that when the Docker engine receives the context package, the deployment will get all the files needed to build the image.

This is the so-called context path, for example, the client is the client's current directory, and in docker server it represents the file path after the docker server is unzipped.

Thank you for reading! This is the end of this article on "how to use docker file to build an image". I hope the above content can be of some help to you, so that you can learn more knowledge. 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report