Create a mirror based on dockerfile

1. Operation command

instruction meaning
FROM mirror Specify the image on which the new image is based. The first instruction must be the FROM instruction. Every time you create an image, you need a FROM instruction.
MAINTAINER first name Describe the maintainer information of the new image
RUN command Execute commands on the mirror on which it is based
CMD ["Command to be executed", "Parameter 1", "Parameter 2"] The command or script to be run when the instruction starts the container, the Dockerfile can only have one CMD command, if multiple ones are specified, only the last one can be executed
EXPOSE port number Specify the port to be opened when the new image is loaded into Docker
ENV environment variable variable value Set the value of an environment variable, which will be used by RUN later
ADD source file/directory target file/directory Copy the source file to the target file, the source file must be located in the same directory as the Dockerfile, or a URL
COPY source file/directory target file/directory Copy the file/directory on the local host to the target location, the source file/directory should be in the same directory as the Dockerfile
VOLUME ["Directory"] Create a mount point in the container
USER username/UID Specify the user when running the container
WORKDIR path Specify the working directory for subsequent RUN, CMD, ENTRYPOINT
ONBUILD command Specify the command to run when the generated image is used as a base image
HEALTHCHECK health examination

Two, create an apache mirror

cd /opt
mkdir apache
vim Dockerfile

FROM centos:7
MAINTAINER zz
RUN yum -y update
RUN yum -y install httpd
EXPOSE 80
ADD index.html /var/www/html/index.html
ADD run.sh /run.sh
RUN chmod +x /run.sh
CMD ["/run.sh"]
echo 'ZZZ' > index.html

vim run.sh
#!/bin/bash
rm -rf /run/httpd/*
exec /usr/sbin/apachectl -D FOREGROUND
docker build -t httpd:centos7 .

docker run -d -p 1111:80 httpd:centos7

Insert picture description here
Insert picture description here

Three, create an SSH mirror

cd /opt
mkdir sshd
cd sshd
vim Dockerfile


FROM centos:7
MAINTAINER ZZZ
RUN yum -y update
RUN yum -y install openssh* net-tools lsof telnet passwd
RUN echo '123123' | passwd --stdin root
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN sed -i '/^session\s\+required\s\+pam_loginuid.so/s/^/#/' /etc/pam.d/sshd
RUN mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.ssh
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]
docker build -f /opt/sshd/Dockerfile -t sshd:new .

docker run -d -p 2222:22 sshd:new

Insert picture description here
Insert picture description here

Fourth, create a systemctl mirror

Build a new image based on the previous image

cd /opt
mkdir systemctl
cd systemctl
vim Dockerfile

FROM sshd:new
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/;for i in *;do [ $i = = \
systemd-tmpfiles-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*;\
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"]
docker build -t systemd:new .

docker run --privileged -tid -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd:new /sbin/init  

docker exec -it ef039a28187b bash

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51616026/article/details/115211048