常用服务软件的镜像制作

常用服务软件的镜像制作

创建ssh镜像

[root@localhost opt]# mkdir sshd
[root@localhost opt]# cd sshd
[root@localhost sshd]# vim Dockerfile
[root@localhost sshd]# docker build -t sshd:new .
Sending build context to Docker daemon  2.048kB
Step 1/11 : FROM centos:7
7: Pulling from library/centos
75f829a71a1c: Pull complete 
Digest: sha256:19a79828ca2e505eaee0ff38c2f3fd9901f4826737295157cc5212b7a372cd2b
Status: Downloaded newer image for centos:7
 ---> 7e6257c9f8d8
Step 2/11 : MAINTAINER The CentOS Project <cloud-centos>
 ---> Running in 95636d6a06b0
Removing intermediate container 95636d6a06b0
.........
.........
---> Running in a5cac998d4a5
Removing intermediate container a5cac998d4a5
 ---> ab762d0bc711
Step 9/11 : RUN mkdir -p /root/.ssh && chown root.root /root &&chmod 700 /root/.ssh
 ---> Running in 0ea5a88dca92
Removing intermediate container 0ea5a88dca92
 ---> 316ad412dfd4
Step 10/11 : EXPOSE 22
 ---> Running in a7e3efba8ff8
Removing intermediate container a7e3efba8ff8
 ---> 68a6b9c01a0b
Step 11/11 : CMD ["/usr/sbin/sshd","-D"]
 ---> Running in e28290827139
Removing intermediate container e28290827139
 ---> d1ad28a65cf4
Successfully built d1ad28a65cf4
Successfully tagged sshd:new

[root@localhost sshd]# docker run -d -P sshd:new
bf5195d33069c2cb814b067482d11768ead5f6d17d27eb7e1ce04f319cb72633
[root@localhost sshd]# docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
bf5195d33069        sshd:new            "/usr/sbin/sshd -D"   7 seconds ago       Up 7 seconds        0.0.0.0:32768->22/tcp   modest_haibt
[root@localhost sshd]# ssh localhost -p 32768
The authenticity of host '[localhost]:32768 ([::1]:32768)' can't be established.
RSA key fingerprint is SHA256:SFQFRppCebtP7bsFbjWlj4Zcc3/2qXwyCUxCY/BhpJk.
RSA key fingerprint is MD5:4c:b2:8f:5c:2b:ad:59:74:97:bf:ef:90:92:3a:63:e4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:32768' (RSA) to the list of known hosts.
root@localhost's password: 
[root@bf5195d33069 ~]# 

这样表示容器可以用

systemctl镜像

[root@localhost opt]# mkdir systemctl
[root@localhost opt]# cd systemctl 
[root@localhost systemctl]# vim Dockerfile
[root@localhost systemctl]# docker build -t systemd:new
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile
[root@localhost systemctl]# docker build -t systemd:new .
Sending build context to Docker daemon   2.56kB
Step 1/5 : FROM sshd:new
 ---> d1ad28a65cf4
Step 2/5 : ENV container docker
 ---> Running in 7f1f78404216
Removing intermediate container 7f1f78404216
 ---> d3d93177cf42
Step 3/5 : 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 /lib/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/*;
 ---> Running in c7e6b8345413
Removing intermediate container c7e6b8345413
 ---> 1836253abb35
Step 4/5 : VOLUME [ "/sys/fs/cgroup" ]
 ---> Running in 46c4b920d27b
Removing intermediate container 46c4b920d27b
 ---> 769d57f93bbd
Step 5/5 : CMD ["/usr/sbin/init"]
 ---> Running in 77265ad0cff7
Removing intermediate container 77265ad0cff7
 ---> 4fbf542e6908
Successfully built 4fbf542e6908
Successfully tagged systemd:new

[root@localhost systemctl]# docker run --privileged -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd:new /sbin/init &

[root@localhost systemctl]# docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
a9e46da78fd9        systemd:new         "/sbin/init"          9 seconds ago       Up 8 seconds        22/tcp                  wonderful_rhodes
bf5195d33069        sshd:new            "/usr/sbin/sshd -D"   54 minutes ago      Up 54 minutes       0.0.0.0:32768->22/tcp   modest_haibt
[root@localhost systemctl]# docker exec -it a9e46da78fd9 bash
[root@a9e46da78fd9 /]# 

这表示容器可以用

nginx镜像
上传nginx-1.12.0.tar.gz到opt目录下

[root@localhost opt]# mkdir nginx
[root@localhost opt]#cd nginx
[root@localhost nginx]#vim Docker
FROM centos:7
MAINTAINER this is nginx image <zhang>
RUN yum -y update
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
RUN useradd -M -s /sbin/nologin nginx
ADD nginx-1.12.0.tar.gz /usr/local/src
WORKDIR /usr/local/src
WORKDIR nginx-1.12.0
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@localhost nginx]#vim run.sh
#!/bin/bash
/usr/local/nginx/sbin/nginx
[root@localhost nginx]#docker build -t nginx:new .
[root@localhost nginx]#docker run -d -P nginx:new
[root@localhost nginx]# docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                                           NAMES
e1ed21764795        nginx:new           "/run.sh"             5 minutes ago       Up 5 minutes        0.0.0.0:32776->80/tcp, 0.0.0.0:32775->443/tcp   blissful_snyder
a9e46da78fd9        systemd:new         "/sbin/init"          2 hours ago         Up 2 hours          22/tcp                                          wonderful_rhodes
bf5195d33069        sshd:new            "/usr/sbin/sshd -D"   3 hours ago         Up 3 hours          0.0.0.0:32768->22/tcp                           modest_haibt

在真机浏览器中输入本机IP:端口号看看是否出现NGINX页面,出现了代表容器可以用

tomcat镜像
上传jdk-8u144-linux-x64.tar.gz 和apache-tomcat-8.5.23.tar.gz到opt目录下

[root@localhost opt]# mkdir tomcat
[root@localhost opt]#cd tomcat

[root@localhost tomcat]#vim Dockerfile
FROM centos:7
MAINTAINER this is nginx image <zhang>
ADD jdk-8u144-linux-x64.tar.gz /usr/local
WORKDIR /usr/local
RUN mv jdk 1.8.0_144 /usr/local/java
ENV JAVA_HOME /usr/local/java
ENV JAVA_BIN /usr/local/java/bin
ENV JRE_HOME /usr/local/java/jre
ENV PATH $PATH:/usr/local/java/bin:/usr/local/java/jre/bin
ENV CLASSPATH /usr/local/java/jre/bin:/usr/local/java/lib:/usr/local/java/jre/lib/charsets.jar
ADD apache-tomcat-8.5.23.tar.gz /usr/local
WORKDIR /usr/local/
RUN mv apache-tomcat-8.5.23 /usr/local/tomcat8
EXPOSE 8080
#CMD ["/usr/local/tomcat8/bin/catalina.sh","run"]
ENTRYPOINT  ["/usr/local/tomcat8/bin/catalina.sh","run"]

[root@localhost tomcat]#docker build -t tomcat:centos .
[root@localhost tomcat]#docker run -d --name tomcat1 -p 1216:8080 -it tomcat:centos
ca68b2160e367af03f7ab8c2dd18ab84e38a26cb902e6cab361380fbdb6d5973
[root@localhost tomcat]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                                           NAMES
ca68b2160e36        tomcat:centos       "/usr/local/tomcat8/…"   7 seconds ago       Up 6 seconds               0.0.0.0:1216->8080/tcp                          tomcat1
f0213e49e1dc        684c05d848f3        "/bin/sh -c 'mv jdk1…"   4 minutes ago       Exited (1) 4 minutes ago                                                   adoring_robinson

在真机浏览器中输入本机IP:端口号看看是否出现tomcat页面,出现了代表容器可以用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值