新浦京81707con > 注册购买 > 创建带Tomcat服务的CentOS Docker镜像

原标题:创建带Tomcat服务的CentOS Docker镜像

浏览次数:119 时间:2019-11-02

在 Ubuntu 15.04 上怎么着设置Docker及主干用法 http://www.linuxidc.com/Linux/2015-09/122885.htm 

Docker 的详尽介绍:请点这里
Docker 的下载地址:请点这里

下载JDK
JDK的下载方式与手工业配置形似。然后解压并活动到/root/tomcat_centos目录下

基础镜像:以镜像centos为底蕴的盛放SSH服务的镜像

java  -version

二、准备Dockerfile
在/root/apache_centos目录新建Dockerfile

Ubuntu使用VNC运转基于Docker的桌面系统  http://www.linuxidc.com/Linux/2015-08/121170.htm 

翻开生成的镜像:

假诺提醒未有ssh命令请安装openssh-clients

3、测试
测试apache

docker run -d -p 2222:22 sshd:dockerfile /usr/sbin/sshd -D

文本内容如下:

本子内容:

[root@localhost apache_centos]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sshd                dockerfile          411d5fb16366        23 hours ago        278 MB
centos              latest              0f73ae75014f        5 weeks ago         172.3 MB
tar -zxvf apache-tomcat-8.0.27.tar.gz
mv apache-tomcat-8.0.27 /usr/local/tomcat
[root@localhost apache_centos]# curl localhost:8000
<html><body><h1>It works!</h1></body></html>

下载Tomcat

Ubuntu使用VNC运转基于Docker的桌面系统  http://www.linuxidc.com/Linux/2015-08/121170.htm 

正文长久更新链接地址:http://www.linuxidc.com/Linux/2016-06/132397.htm

#新生成的镜像是基于sshd:dockerfile镜像
FROM sshd:dockerfile
MAINTAINER by Steven
#安装wget
RUN yum install -y wget
WORKDIR /usr/local/src
#下载并解压源码包
RUN wget http://apache.fayea.com/httpd/httpd-2.4.17.tar.gz
RUN tar -zxvf httpd-2.4.17.tar.gz
WORKDIR httpd-2.4.17
#编译安装apache
RUN yum install -y gcc make apr-devel apr apr-util apr-util-devel pcre-devel
RUN ./configure --prefix=/usr/local/apache2  --enable-mods-shared=most  --enable-so
RUN make
RUN make install
#修改apache配置文件
RUN sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /usr/local/apache2/conf/httpd.conf
#启动apache服务
RUN /usr/local/apache2/bin/httpd
#复制服务启动脚本并设置权限
ADD run.sh /usr/local/sbin/run.sh
RUN chmod 755 /usr/local/sbin/run.sh
#开放80端口
EXPOSE 80
CMD ["/usr/local/sbin/run.sh"]

查阅进程

[root@localhost apache_centos]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
apache_dockerfile   centos              f8f30b4a0ee8        24 minutes ago      440 MB
apache              centos              f92c55dddd07        17 hours ago        423.9 MB
sshd                dockerfile          411d5fb16366        23 hours ago        278 MB
centos              latest              0f73ae75014f        5 weeks ago         172.3 MB
. /etc/profile.d/java.sh

如上文件都放置/root/apache_centos目录下

3、Dockerfile内容

使用Dockerfile创建带Apache服务的CentOS Docker镜像

#!/bin/bash
/usr/sbin/sshd -D &
/usr/local/tomcat/bin/catalina.sh run

成功!
测试ssh

图片 1

[root@localhost apache_centos]# docker ps -a
CONTAINER ID        IMAGE                      COMMAND                CREATED             STATUS                      PORTS                                        NAMES
ae560e497f39        apache_dockerfile:centos   "/usr/local/sbin/run   45 seconds ago      Up 44 seconds               0.0.0.0:2222->22/tcp, 0.0.0.0:8000->80/tcp   condescending_bardeen
6490cd244c10        apache:centos              "/usr/local/apache2/   17 hours ago        Exited (0) 17 hours ago                                                  loving_wright
673e946b57e4        sshd:dockerfile            "/usr/local/sbin/run   18 hours ago        Exited (137) 17 hours ago                                                reverent_bell
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sshd                dockerfile          411d5fb16366        2 days ago          278 MB
centos              latest              0f73ae75014f        5 weeks ago         172.3 MB

Docker安装应用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm 

四、安装JDK

2、查看新生成的器皿:

七、生成镜像
1、退出容器,运营下边包车型大巴一声令下查看窗口消息

剧情如下:

mkdir /root/tomcat_centos
cd /root/tomcat_centos
touch Dockerfile run.sh
vim run.sh
[root@localhost ~]# docker commit bdde7d657620 tomcat:centos
d2f8ec74f011e5bcd0b544b251cc120a31e53411f6ab2904c103c5f3a759096d

Ali云CentOS 6.5 模板上设置 Docker http://www.linuxidc.com/Linux/2014-11/109107.htm 

tar -zxvf jdk-8u60-linux-x64.tar.gz

四、依据镜像生成的器皿并实行测验
1、生成新的器皿

tar -zxvf jdk-8u60-linux-x64.tar.gz
mv jdk1.8.0_60 /usr/local/jdk1.8.0_60
 docker run -d -p 2222:22 -p 8000:80 apache_dockerfile:centos /usr/local/sbin/run.sh

独家映射容器的22、8080端口给宿主机的2223、8081端口,并运维运转脚本。
查阅新生成的容器:

将容器的22端口和80端口分别映射到到宿主机上的2222端口和8000端口,并运转服务脚本。

#新生成的镜像是基于sshd-centos镜像
FROM sshd-centos
MAINTAINER by cmsteven
WORKDIR /usr/local/src
#安装wget
RUN yum install -y wget
#下载tomcat源码包
RUN wget http://apache.fayea.com/tomcat/tomcat-8/v8.0.27/bin/apache-tomcat-8.0.27.tar.gz
#从宿主机上复制JDK文件夹
ADD jdk1.8.0_60 /usr/local/jdk1.8.0_60
#配置JDK环境脚本
RUN touch  /etc/profile.d/java.sh
RUN echo "JAVA_HOME=/usr/local/jdk1.8.0_60" >> /etc/profile.d/java.sh
RUN echo "JAVA_BIN=/usr/local/jdk1.8.0_60/bin" >> /etc/profile.d/java.sh
RUN echo "JRE_HOME=/usr/local/jdk1.8.0_60/jre" >> /etc/profile.d/java.sh
RUN echo "PATH=$PATH:/usr/local/jdk1.8.0_60/bin:/usr/local/jdk1.8.0_60/jre/bin" >> /etc/profile.d/java.sh
RUN echo "CLASSPATH=/usr/local/jdk1.8.0_60/jre/lib:/usr/local/jdk1.8.0_60/lib:/usr/local/jdk1.8.0_60/jre/lib/charsets.jar" >> /etc/profile.d/java.sh
#导入JDK环境
RUN . /etc/profile.d/java.sh
#解压tomcat源码包
RUN tar -zxvf /usr/local/src/apache-tomcat-8.0.27.tar.gz
RUN mv /usr/local/src/apache-tomcat-8.0.27 /usr/local/tomcat
#修改tomcat启动脚本
WORKDIR /usr/local/tomcat/bin
RUN cp  /usr/local/tomcat/bin/catalina.sh  /usr/local/tomcat/bin/catalina.sh.bak
RUN > /usr/local/tomcat/bin/catalina.sh
RUN echo '#!/bin/sh'>> /usr/local/tomcat/bin/catalina.sh
RUN echo "JAVA_HOME=/usr/local/jdk1.8.0_60">> /usr/local/tomcat/bin/catalina.sh
RUN echo "CATALINA_HOME=/usr/local/tomcat" >>  /usr/local/tomcat/bin/catalina.sh
RUN grep -v '^#!/bin/sh' catalina.sh.bak >>  /usr/local/tomcat/bin/catalina.sh
#启动tomcat服务
RUN  /usr/local/tomcat/bin/catalina.sh start
#复制容器启动脚本
ADD run.sh /usr/local/sbin/run.sh
#设置脚本权限
RUN chmod 755 /usr/local/sbin/run.sh
CMD ["/usr/local/sbin/run.sh"]
#开放容器的22和8080端口
EXPOSE 8080
EXPOSE 22
vim Dockerfile

3、查看镜像

在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker http://www.linuxidc.com/Linux/2014-10/108184.htm 

2、生成镜像

一、准备run.sh文件
在/root/apache_centos目录新建run.sh

Ubuntu 15.04下安装Docker  http://www.linuxidc.com/Linux/2015-07/120444.htm 

Dockerfile
#启动ssh和apache服务的角本
run.sh

2,run.sh脚本内容:

mkdir -p /root/apache_centos
cd /root/apache_centos

4、根据新生成的镜像生成容器

[root@localhost apache_centos]# ssh localhost -p 2222
root@localhost's password:
cd /usr/local/tomcat/bin
cp catalina.sh catalina.sh.bak
>catalina.sh
echo '#!/bin/sh'>>catalina.sh
echo "JAVA_HOME=/usr/local/jdk1.8.0_60">>catalina.sh
echo "CATALINA_HOME=/usr/local/tomcat" >> catalina.sh
grep -v '^#!/bin/sh' catalina.sh.bak >> catalina.sh

图片 2

2、配置JDK境况脚本

成功!

越多Docker相关教程见以下内容: 

正文长久更新链接地址:http://www.linuxidc.com/Linux/2016-06/132399.htm

2、改正配置文件

在宿主机上图谋的文才具项清单:

Docker 的详细介绍:请点这里
Docker 的下载地址:请点这里

更加多Docker相关教程见以下内容: 

在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker http://www.linuxidc.com/Linux/2014-10/108184.htm 

docker build -t apache_dockerfile:centos .

三、下载源码包及相关软件
1、安装wget

亟需在意的是:在Dockerfile文件中改造当前目录不得以用“cd”命令,而要改用“WO奥迪Q5KDIEscort”.
三、生成镜像

wget --no-check-certificate -c --header "Cookie: Oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u60-
b27/jdk-8u60-linux-x64.tar.gz

Ubuntu 14.04安装Docker  http://www.linuxidc.com/linux/2014-08/105656.htm 

本文由新浦京81707con发布于注册购买,转载请注明出处:创建带Tomcat服务的CentOS Docker镜像

关键词: 新浦京81707con

上一篇:CentOS 7.2 安装Smokeping

下一篇:没有了