今天也来点Docker,Dockerfile镜像制作

一、SSH的镜像制作

[root@docker ~]# mkdir sshd
[root@docker ~]# cd sshd/
[root@docker sshd]# vi Dockerfile
FROM centos:7
MAINTAINER Made By HYC
RUN yum -y update
RUN yum -y install openssh* net-tools lsof telnet passwd
RUN echo '123456' | 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"]

[root@docker sshd]# docker build -t sshd:new .
[root@docker sshd]# docker run -d -P sshd:new
840737a227883c85b3e89dde82e96e9391f91e1ce9cd976bd67e7ca206541162
[root@docker sshd]# docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
840737a22788        sshd:new            "/usr/sbin/sshd -D"   6 seconds ago       Up 5 seconds        0.0.0.0:32769->22/tcp   admiring_ganguly

在这里插入图片描述

二、Systemctl的镜像制作

基于sshd镜像搭建,让其能使用systemctl这个命令

[root@docker ~]# mkdir systemctl
[root@docker ~]# cd systemctl/
[root@docker systemctl]# vi Dockerfile
FROM sshd:new
MAINTAINER Made By HYC
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"]

[root@docker systemctl]# docker build -t systemd:new .
[root@docker systemctl]# docker run --privileged -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd:new /sbin/init &
[root@docker systemctl]# docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
a87858dc1855        systemd:new         "/sbin/init"          36 seconds ago      Up 35 seconds       22/tcp                  intelligent_brahmagupta
[root@docker systemctl]# docker exec -it a87858dc1855 bash

在这里插入图片描述

三、Nginx的镜像制作

[root@docker ~]# mkdir nginx
[root@docker ~]# cd nginx/
[root@docker nginx]# vi Dockerfile
From centos:7
MAINTAINER Made By HYC
RUN yum -y update
RUN yum -y install gcc gcc-c++ zlib-devel pcre-devel make
RUN useradd -M -s /sbin/nologin nginx
ADD nginx-1.12.2.tar.gz /usr/local/src
WORKDIR /usr/local/src
WORKDIR nginx-1.12.2
RUN ./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
EXPOSE 443
RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf              
ADD run.sh /run.sh
RUN chmod 755 /run.sh
CMD ["/run.sh"]

在这里插入图片描述

[root@docker nginx]# vi run.sh
#!/bin/bash
/usr/local/nginx/sbin/nginx
[root@docker nginx]# docker build -t nginx:new .
[root@docker nginx]# docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                                           NAMES
2be5b2564684        nginx:new           "/run.sh"             10 seconds ago      Up 9 seconds        0.0.0.0:32771->80/tcp, 0.0.0.0:32770->443/tcp   recursing_proskuriakova

在这里插入图片描述

四、Tomcat的镜像制作

[root@docker ~]# mkdir tomcat
[root@docker ~]# cd tomcat/
[root@docker tomcat]# vi Dockerfile
From centos:7
MAINTAINER Made By HYC
ADD jdk-8u91-linux-x64.tar.gz /opt/
RUN mv /opt/jdk1.8.0_91/ /usr/local/java
ENV JAVA_HOME /usr/local/java
ENV CLASSPATH $JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
ENV PATH $JAVA_HOME/bin:$PATH
ADD apache-tomcat-8.5.16.tar.gz /usr/local/src
RUN mv /usr/local/src/apache-tomcat-8.5.16 /usr/local/tomcat
EXPOSE 8080
CMD ["/usr/local/tomcat/bin/catalina.sh","run"]

在这里插入图片描述

[root@docker tomcat]# docker build -t tomcat:new .
[root@docker tomcat]# docker run -d -P --name tomcat tomcat:new
[root@docker tomcat]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                                           NAMES
541865934ef9        tomcat:new          "/usr/local/tomcat/b…"   About a minute ago   Up About a minute   0.0.0.0:32772->8080/tcp                         tomcat

在这里插入图片描述

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 黑客帝国 设计师:上身试试 返回首页