In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge about "how to create a new Docker image". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
One way we build docker images using Dockerfile is to use official preconfigured container images. The advantage was that we didn't have to build from scratch, which saved us a lot of effort, but at the cost of downloading large mirror packages.
For example, docker images on my machine returned these nginx based images, each of which exceeded 100MB, while a simple Ubuntu container exceeded 200MB, and the size would be larger if the relevant software was installed.
If our requirement is to make sure the image size is as small as possible while building a Docker image that matches our actual business needs, what should we do?
The idea is to use an empty mirror scratch.
Create a new folder and download rootfs.tar.xz with wget.
wget -O otfs.tar.xz https://github.com/debuerreotype/docker-debian-artifacts/raw/b024a792c752a5c6ccc422152ab0fd7197ae8860/jessie/rootfs.tar.xz
What is this nearly 30MB compressed package?
After decompression, you can see the content, which contains most of the common commands of the operating system.
wget -O nginx.conf https://github.diablo.corp/raw/slvi/docker-k8s-training/master/docker/res/nginx.conf
Create a dockerfile and paste the following into it:
FROM scratch# set the environment to honour SAP's proxy serversENV http_proxy http://sap.corp:8080ENV https_proxy http://sap.corp:8080ENV no_proxy .sap.corp# give yourself some creditLABEL maintainer="Jerry Wang"# add and unpack an archive that contains a Debian root filesystemADD rootfs.tar.xz /# use the apt-get package manager to install nginx and wgetRUN apt-get update && \apt-get -y install nginx wget# use wget to download a custom website into the imageRUN wget --no-check-certificate -O /usr/share/nginx/html/cheers.jpg https://github.diablo.corp/raw/slvi/docker-k8s-training/master/docker/res/cheers.jpg && \wget --no-check-certificate -O /usr/share/nginx/html/index.html https://github.diablo.corp/raw/slvi/docker-k8s-training/master/docker/res/cheers.html# copy the custom nginx configuration into the imageCOPY nginx.conf /etc/nginx/nginx.conf# link nginx log files to Docker log collection facilityRUN ln -sf /dev/stdout /var/log/nginx/access.log && \ln -sf /dev/stderr /var/log/nginx/error.log# expose port 80 - the standard port for webserversEXPOSE 80# and make sure that nginx runs when a container is createdCMD ["nginx", "-g", "daemon off;"]
Execute the command to build a mirror:
docker build -t nginx-from-scratch2.0 .
Log generated:
Finally, I see the message that the mirror was successfully built.
Start a new nginx container based on this image named nginx-from-scratch:
localhost:1083, see the home page, indicating that this newly built image works fine.
"How to create a new Docker image" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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: 305
*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.