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 use Dockerfile to build an image

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article focuses on "how to use Dockerfile to build an image", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Dockerfile to build an image.

Prepare # create a new folder for building the image, put all the files you need in the new folder cd ~ & & mkdir test # create or copy the files to be packaged into the image, (the following is the author's own test file) touch test.sh echo "this is a test shell" > test.sh # New Dockerfile touch Dockerfile # preparation is complete. Write Dockerfile# basic image FROM ubuntu:latest# contributor MAINTAINER wanglihui "lihui.wang@jingli.tech" # initialize the container environment RUN mkdir / home/wwwRUN apt-get update# here you can install the image via RUN depending on # RUN apt-get install-y nodejs#RUN apt-get install-y npm#RUN apt-get install-y gitADD. / test.sh / home/www/# can add packaged format files that can be recognized by the system Will automatically extract to the relevant directory # ADD. / test.tar.gz / home/www/#WORKDIR similar to cd on linux can switch the working directory WORKDIR / home/www/# when launching the container, execute the command CMD ["sh", "test.sh"] # expose the port number # EXPOSE 8080 to build the image #-t to specify the image tag The format is owner: image name docker build-t wanglihui:test test/ using image docker run wanglihui:test # you can see that the console outputs other common this is a test shell commands 1. Docker run with docker run common parameters are-p bind port number-p external port number: internal port-link link two containers-env key=value injection container variable 2. Docker ps view running containers-a view all containers 3. Docker images-- list all images 4. Docker start container ID docker stop container ID here I believe you have a deeper understanding of "how to use Dockerfile to build an image". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Servers

Wechat

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

12
Report