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

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use dockerfile". In daily operation, I believe many people have doubts about how to use dockerfile. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use dockerfile"! Next, please follow the editor to study!

Use dockerfile

It is more intuitive to create an image in docker commit. But it is not easy to distribute and share. Another method that is more commonly used is to use dockerfile

Create two new directories and create two files

[root@srv00 ~] # mkdir df & & cd df [root@srv00 df] # cat nginx.repo [nginx] name=nginx repobaseurl= http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1[root@srv00 df] # cat Dockerfile FROM centos:latestMAINTAINER hippo COPY nginx.repo / etc/yum.repos.d/RUN yum install-y nginx & & echo "daemon off;" > > / etc/nginx/nginx.conf EXPOSE 80CMD ["nginx"]

Dockerfile is the default file name, docker build-f to specify the custom file one instruction per line. Kind of like shell. FROM based on which image .MAINTAINER maintainer maintainer information. Copy copy the local files to the image directory. The command that RUN runs in the mirror. EXPOSE exposes port numbers to external mapping.CMD commands that will be executed if the container is run. (console execution. Otherwise, the container will exit immediately.

Run docker build

[root@srv00 df] # docker build-t hippo/nginx:v1 .Sending build context to Docker daemon 3.072 kBStep 1: FROM centos:latest-> 8596123a638eStep 2: MAINTAINER hippo-> Using cache-> c04988102337Step 3: COPY nginx.repo / etc/yum.repos.d/-> 840a6358f3d1Removing intermediate container 8cb81de3f7e9Step 4: RUN yum install-y nginx & & echo "daemon off "> > / etc/nginx/nginx.conf-- > Running in 5a27d8a4bc77Loaded plugins: fastestmirror, ovl.Complete!-- > 45b53927ed9aRemoving intermediate container 5a27d8a4bc77Step 5: EXPOSE 80-> Running in f022d6097efa-> 29429605ebc7Removing intermediate container f022d6097efaStep 6: CMD nginx-> Running in c7faa5042715-- > 2e1513eeaa0aRemoving intermediate container c7faa5042715Successfully built 2e1513eeaa0a

Each instruction is equivalent to one git commit.

Run the test

[root@srv00 df] # docker run-d-p 80 hippo/nginx:v1dead20777b6c1609ab968966b3589904d44f8a12c124c178fd5cb540052cce6f [root@srv00 df] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESdead20777b6c hippo/nginx:v1 "nginx" 11 seconds ago Up 8 seconds 0.0.0.0 hippo/nginx:v1dead20777b6c1609ab968966b3589904d44f8a12c124c178fd5cb540052cce6f 32771- > 80/tcp gloomy_ Cray [root @ srv00 df] # curl-L localhost:32771Welcome to nginxcake. At this point, the study on "how to use dockerfile" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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