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

Make an image by Docker

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

Share

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

Docker making mirroring hierarchical Dockerfile basic creation method of Docker image Dockerfile creating a variety of application container Docker images each instruction in the hierarchical Dockerfile will create a new mirror layer the mirror layer will be cached and reused when the Dockerfile instruction is modified, the copied file changes, or the specified variables are different when building the image, the corresponding image cache will be invalidated after a certain layer of image cache fails. Its mirror layer cache will fail. The mirror layer is immutable. If you add a file to one layer, then delete it in the next layer. Then the image will still contain the file Docker image creation Docker image is a standard format for application release that can support a Docker container running Docker image creation method based on existing image creation based on local template creation based on existing image creation based on existing image package of programs and running environments running in the container to generate a new image docker create-it centos / bin/bashdocker commit-m "new"-a "daoke" a19597abf62d daoke:centos-m: description information-a: author information-p: stop the operation of the container during generation based on the local template to create a new image by importing the operating system template file to generate a new image using the wget command to import as a local image wget http://123.56.134.27/pub/package/LAMP-C7/nginx-1.12.0.tar.gzcat nginx-1.12.0.tar.gz | docker import -after the docker:new is imported successfully, you can view the local image information docker images | grep new based on Dockerfile to create Dockerfile is a file composed of a set of instructions. Dockerfile result four parts basic impact Information maintainer Information Mirror Operation instruction Container starts to execute instructions to create an image using Dockerfile and run the instruction meaning FROM image in the container to specify the image on which the new image is based The first instruction must be a FROM instruction, and a FFROM instruction is required for each image created. MAINTAINER name indicates the maintainer information of the new image RUN command executes the command on the image on which it is based, and submits it to the new image CMD ["Program to run", "Parameter 1, Parameter 2"] command to run when starting the container. Dockerfile can only have one CMD command. If multiple entries are specified, only the last f can be executed by the EXPOSE port number to specify the port to be opened when the new image is loaded into Docker. The variable value of the ENV environment variable sets the value of an environment variable. The later RUN will use the ADD source file / directory target file / directory to copy the source file to the destination file, and the source file should be located in the same directory as Dockerfile. Or f URLCOPY source file / directory destination file / directory copy the file / directory on the local host to the destination location The source file / directory should be in the same directory as DGckerfile VOLUME ["directory"] create a mount point in the container USER username / UID specifies that the user WORKDIR path when running the container is the subsequent RUN, CMD, ENTRYPOINT specify working directory command ONBUILD commands to run when the generated image is used as a basic image HEALTHCHECK health check Dockerfile create various application containers Dockerfile create apache image container mkdir apachecd apache/vim Dockerfile# based basic image FROM centos# maintenance image user information MAINTAINER The project # image operation instructions install apache software RUN yum-y update / / update yum repository RUN yum-y install httpd# open 80 Copy the website homepage file ADD index.html/ var/www/html/index.html# to copy the execution script to the mirror ADD run.sh / run.shRUN chmod 755 / run.sh# start the container, execute the script CMD ["/ run.sh"] [root@localhost opt] # vim run.shangxinxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Docker build-t httpd:centos. / / New image operation container docker run-d-p 1216 httpd:centosDockerfile create ssh image container mkdir sshdcd sshd/vim Dockerfile# based basic image FROM centos# maintain image user information MAINTAINER this is project # reload yum source RUN yum-y update# install the necessary software package RUN yum-y install openssh* net-tools lsof telnet passwd# set the password RUN echo '123456' for root users | passwd-- stdin root # modify the configuration file RUN sed-I 's/UsePAM yes/UsePAM no/g' / etc/ssh/sshd_config# to generate the key RUN ssh-keygen-t rsa-f / etc/ssh/sshd_host_rsa_keyRUN sed-I' / ^ scssion\ s\ + required\ s\ + pam_loginuid.so/s/ ^ / # /'/ etc/pam.d/sshdRUN mkdir-P / root/.ssh & & chown root.root / root & & chmod 700 / root/.ssh# 20-port EXPOSE 2 launch container CMD ["/ usr/sbin/sshd" "- D"] / / generate image docker build-t sshd:new. / / launch the container and modify the root password docker run-d-P sshd:newssh localhost-p 32770Dockerfile based on the sshd image container to create the basic image FROM sshd:newENV container dockerRUN (cd / lib/systemd/system/sysinit.target.wants/) on which the systemctl image container mkdir systemctl cd systemctl vim Dockerfile# is based For i in *; do [$I = =\ systemd-tmpfile-setup.service] | | rm-f $I; done);\ rm-f / lib/systemd/system/multi-user.target.wants/*;\ rm-f / etc/systemd/system/*.wants/*;\ rm-f / lib/systemd/system/local-fs.target.wants/*;\ rm-f / lib/systemd/system/sockets.target.wants/*udev* The root in\ rm-f / lib/systemd/system/sockets.target.wants/*initctl*;\ rm-f / lib/systemd/system/basic.target.wants/*;\ rm-f / lib/systemd/system/anaconda.target.wants/*;VOLUME ["/ sys/fs/cgroup"] CMD ["/ usr/sbin/init"] / / generated image docker build-t local/c7-systemd:latest. / / privileged container has real root permissions. Otherwise, the root in the container is just an external docker run with ordinary user rights-- privileged-ti-v / sys/fs/cgroup:sys/fs/cgroup:ro local/c7-systemd:latest / sbin/init// enters the container docker exec-it image IP bash

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