`

Docker安装Java, Apache, Redis, Tomcat, Postgresql, SSH

 
阅读更多
centos安装redis3为系统服务 http://my.oschina.net/haoqoo/blog/464247


centos 安装Supervisor
http://www.alphadevx.com/a/455-Installing-Supervisor-and-Superlance-on-CentOS
网络设定
# 创建网络
brctl addbr br0
ip link set dev br0 up
ip addr add 192.168.2.1/24 dev br0

# 创建容器
# 方法1
DB=$(docker run -d --name db pandy/centos7-postgresql931)
pipework br0 $DB 192.168.2.100/24
# 方法2
docker run -d --name db pandy/centos7-postgresql931
pipework br0 db 192.168.2.100/24

# 删除容器之后删除网络
ip link set br0 down
brctl delbr br0


SSH
*********************************************************************
Dockerfile
====================
FROM centos:centos7
MAINTAINER Pandy  <panyongzheng@163.com>

RUN yum update -y
RUN yum install -y openssh-server which
RUN mkdir -p /var/run/sshd && \
    echo "root:root" | chpasswd
ADD init-functions /etc/rc.d/init.d/functions
RUN /usr/sbin/sshd-keygen
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
CMD /usr/sbin/sshd -D

EXPOSE 22

构建:
docker build -t pandy/ssh .
docker run -d -name ssh pandy/ssh
pipework br0 apache 192.168.2.103/24;





Java
*********************************************************************
官方openJDK: https://registry.hub.docker.com/_/java/
OracleJDK: https://registry.hub.docker.com/u/alsanium/java/
centos oracleJDK https://registry.hub.docker.com/u/j728c/java/dockerfile/, 里面应该继续支持解压和压缩:yum -y install tar zip unzip
自己修改后的Dockerfile
====================================
FROM centos:centos7
MAINTAINER Pandy  <panyongzheng@163.com>

# update repo
RUN yum -y update
RUN yum -y install supervisor

# install jdk then remove the rpm
#RUN yum install -y wget && wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.rpm 
#RUN rpm -Uvh jdk-7u75-linux-x64.rpm && rm jdk-7u75-linux-x64.rpm 
# set JAVA_HOME, CLASSPATH, PATH 
#ENV JAVA_HOME /usr/java/jdk1.7.0_75

COPY jdk-7u72-linux-x64.rpm /tmp/jdk-7u72-linux-x64.rpm
RUN rpm -ivh /tmp/jdk-7u72-linux-x64.rpm && rm /tmp/jdk-7u72-linux-x64.rpm
ENV JAVA_HOME /usr/java/jdk1.7.0_72

#TEST
RUN java -version
RUN javac -version

# install tar,zip,unzip
RUN yum -y install tar zip unzip

构建:docker build -t pandy/centos7-java7 .
使用:docker run -t -i xxx/xxxx /bin/bash




Apache
*********************************************************************
Dockerfile参考: https://registry.hub.docker.com/u/skydiverss/apache-centos/dockerfile/
FROM centos:centos7
MAINTAINER Pandy <panyongzheng@163.com>

# Update latest packages
RUN yum -y update

#COMMON
#==============================================
#RUN yum -y install vim

# Install REMI and EPEL repositories
#RUN yum -y install localinstall http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
#RUN yum -y localinstall http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
COPY epel-release-6-8.noarch.rpm /tmp/epel-release-6-8.noarch.rpm
RUN rpm -Uvh /tmp/epel-release-6-8.noarch.rpm && rm /tmp/epel-release-6-8.noarch.rpm

# Install httpd, php 5.4 and extensions
RUN yum list httpd
RUN yum -y --enablerepo=remi install httpd

# Clean yum cache
RUN yum clean all

#Add Apache an PHP config files whith variables
#ADD httpd.conf /etc/httpd/conf/httpd.conf


#Apache ENV
ENV APACHE_TIMEOUT 60
ENV APACHE_KEEPALIVE Off
ENV APACHE_MAXKEEPALIVEREQUESTS 100
ENV APACHE_KEEPALIVETIMEOUT 15
ENV APACHE_DEFAULT_LOGS_DIR logs
ENV APACHE_SERVERADMIN root@localhost
ENV APACHE_DEFAULT_LOGS_LEVEL warn

#PHP ENV
ENV PHP_SHORTOPENTAG Off
ENV PHP_MEMORYLIMIT 128M
ENV PHP_DISPLAYERROR Off

EXPOSE 80

VOLUME  ["/var/www/html","/var/www/cgi-bin"]

CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]

构建

docker build -t pandy/apache .
docker run -d -p 81:80 -e SERVERADMIN="mail@domain.com" -e DEFAULT_LOGS_DIR="/logs/httpd/defaults" --name=apache -v /home/pandy/docker-resources/apache/conf:/etc/httpd/conf -v /home/pandy/docker-resources/apache/html:/var/www/html pandy/apache  //这里不用后面的一些命令, 会自动调用Dockerfile里面的CMD内容




Memcached, 注意,这个没测试成功.
*********************************************************************
Dockerfile参考: https://registry.hub.docker.com/u/centminmod/docker-centos7-memcached/
FROM centos:centos7
MAINTAINER Pandy <panyongzheng@163.com>

#Commom
RUN yum -y update

# Setup Memcached
RUN yum -y install epel-release nano which hostname && rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm && yum update -y && yum install -y memcached --enablerepo=remi && yum clean all && rm -rf /var/cache/* && echo "" > /var/log/yum.log

# Clean yum cache  
RUN yum clean all

# Expose 11211 to outside
EXPOSE 11211

# Service to run
CMD /usr/bin/memcached -m 64 -p 11211 -c 4096 -b 4096 -t 2 -R 200 -n 72 -f 1.25 -u memcached -o slab_reassign slab_automove

构建 参考 https://registry.hub.docker.com/u/centminmod/docker-centos7-memcached/

docker build -t pandy/memcached .
docker run --name memcached -d -p 33211:11211 -t pandy/memcached memcached -m 512 -t 2

memcached命令详解:http://nkcoder.github.io/blog/20140215/memcached-usage-parameters-commands/





Redis
*********************************************************************
Dockerfile参考: https://registry.hub.docker.com/u/zhaowh/centos-redis/dockerfile/
FROM centos:centos7

MAINTAINER  Pandy <panyongzheng@163.com>


RUN yum -y update

# Install gcc
#RUN yum -y install localinstall http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
#RUN yum -y localinstall http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
COPY epel-release-6-8.noarch.rpm /tmp/epel-release-6-8.noarch.rpm
RUN rpm -Uvh /tmp/epel-release-6-8.noarch.rpm && rm /tmp/epel-release-6-8.noarch.rpm
RUN yum -y install wget tar gcc-c++ automake autoconf libtool make

#安装Supervisor  
#===============================================  
#RUN yum -y install supervisor  
RUN yum install -y python-setuptools  
RUN easy_install supervisor  
RUN supervisord --version 

RUN yum clean all
                                                                                                                      
# Install Redis.
COPY redis-stable.tar.gz /tmp/redis-stable.tar.gz

RUN \
  cd /tmp && \
#  wget http://download.redis.io/redis-stable.tar.gz && \ #注释掉了
  tar xvzf redis-stable.tar.gz && \
  cd redis-stable && \
  make && \
  make install && \
  cp -f src/redis-sentinel /usr/local/bin && \
  mkdir -p /etc/redis && \
  cp -f *.conf /etc/redis && \
  rm -rf /tmp/redis-stable* && \
  sed -i 's/^\(bind .*\)$/# \1/' /etc/redis/redis.conf && \
  sed -i 's/^\(daemonize .*\)$/# \1/' /etc/redis/redis.conf && \
  sed -i 's/^\(dir .*\)$/# \1\ndir \/data/' /etc/redis/redis.conf && \
  sed -i 's/^\(logfile .*\)$/# \1/' /etc/redis/redis.conf

VOLUME ["/data"]
WORKDIR /data
EXPOSE 6379

#启动命令:redis-server /etc/redis/redis.conf
#CMD ["redis-server", "/etc/redis/redis.conf"]
COPY supervisord-redis.conf /etc/supervisord.conf
#启动supervisord  
CMD ["/usr/bin/supervisord"]

构建

docker build -t pandy/redis .
docker run -d -p 6379:6379 pandy/redis


Tomcat
*********************************************************************
官方:https://registry.hub.docker.com/_/tomcat/
centos例子:
1. https://registry.hub.docker.com/u/consol/tomcat-7.0/dockerfile/
2. https://registry.hub.docker.com/u/malderhout/tomcat/dockerfile/
, 里面应该继续支持解压和压缩:yum -y install tar zip unzip
自己修改后的Dockerfile
====================================
FROM centos:centos7 
MAINTAINER Pandy  <panyongzheng@163.com>

# UPDATE
RUN yum -y update

#安装Supervisor
#===============================================
#RUN yum -y install supervisor
RUN yum install -y python-setuptools
RUN easy_install supervisor
RUN supervisord --version

#Common
#===============================================
# INSTALL packages 
RUN yum -y install wget tar zip unzip

#Java
#===============================================
#RUN yum install -y wget && wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.rpm 
#RUN rpm -Uvh jdk-7u75-linux-x64.rpm && rm jdk-7u75-linux-x64.rpm 
# set JAVA_HOME, CLASSPATH, PATH 
#ENV JAVA_HOME /usr/java/jdk1.7.0_75

COPY jdk-7u72-linux-x64.rpm /tmp/jdk-7u72-linux-x64.rpm
RUN rpm -ivh /tmp/jdk-7u72-linux-x64.rpm && rm /tmp/jdk-7u72-linux-x64.rpm
ENV JAVA_HOME /usr/java/jdk1.7.0_72
#TEST
RUN java -version
RUN javac -version


#Tomcat
#===============================================
# TOMCAT version
ENV TOMCAT_VERSION 7.0.61

# INSTALL TOMCAT
#RUN wget -q https://archive.apache.org/dist/tomcat/tomcat-7/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz -O /tmp/tomcat7.tar.gz
COPY apache-tomcat-7.0.61.tar.gz /tmp/tomcat7.tar.gz

# UNPACK
RUN tar xzf /tmp/tomcat7.tar.gz -C /opt
RUN ln -s /opt/apache-tomcat-${TOMCAT_VERSION} /opt/tomcat
RUN rm /tmp/tomcat7.tar.gz

# REMOVE APPS 删除不必要的应用
RUN rm -rf /opt/tomcat/webapps/examples /opt/tomcat/webapps/docs 

# Add roles, 手动下载对应版本的tomcat, 然后修改tomcat-users.xml, 在进行覆盖
#ADD tomcat-users.xml /opt/tomcat/conf/

# SET CATALINE_HOME and PATH 
ENV CATALINA_HOME /opt/tomcat
ENV PATH $PATH:$CATALINA_HOME/bin

#copy conf to image 位置为其中之一, 推荐使用最后一个:
#etc/supervisord.conf,  supervisord.conf, supervisord.conf, 
#etc/supervisord.conf, /etc/supervisord.conf
#COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY supervisord-tomcat.conf /etc/supervisord.conf

# SET PORT and start TOMCAT
EXPOSE 22 80 8080

#启动supervisord
CMD ["/usr/bin/supervisord"]

#启动Tomcat, 已经启动了supervisord, 那么这里是否还需要? 待确定.
#CMD $CATALINA_HOME/bin/catalina.sh run
#CMD $CATALINA_HOME/bin/startup.sh

supervisord.conf文件代码
[supervisord]
nodaemon=true

[program:tomcat]
command=/opt/tomcat/bin/startup.sh

构建:
docker build -t pandy/centos7-java7-tomcat7 .   //构建
docker run -t -i -d --name web -p 81:8080 pandy/centos7-java7-tomcat7 /bin/bash //创建, 这个不会自动启动tomcat
docker run -d --name web -p 81:8080 pandy/centos7-java7-tomcat7 /usr/bin/supervisord  //这个会自动启动tomcat
docker run -t -d --name web -p 81:8080 -v /home/pandy/docker-resources/tomcat/webapps:/opt/tomcat/webapps pandy/centos7-java7-tomcat7 /usr/bin/supervisord  //这个会自动启动tomcat, 并挂载webapps, 同时可以挂载logs, work等文件夹进去,注意,现在为什么挂载要使用/opt/tomcat7,而不是/opt/tomcat?不是已经做软链接了么?

注意:关于tomcat,在http://support.inovatrend.com/confluence/display/PUBLOG/Java,+Tomcat+and+Docker,介绍
比如:在run追加参数-e "JAVA_OPTS=-Dspring.profiles.active=demo -Xmx1024m", 可以设定一些变量.
但是https://registry.hub.docker.com/u/maluuba/tomcat7/看到
docker run --cap-add SYS_PTRACE -it -p 8080:8080 -e JAVA_OPTS='-Dsome.property=value' -e Xmx=2048m -v deployment:/deployment maluuba/tomcat7
待测试看到底是哪种情况是对的




Postgresql
*********************************************************************
原文:https://registry.hub.docker.com/u/autenta/centos-postgresql/
Image for CentOS 6 and PostgreSQL 9.3 that create database with sv_SE.UTF8 locale.
Source: https://github.com/jotu/docker-centos-postgresql

OBS! This is a simple version and should only be used in development or testing.
Getting Started
You can build this container from Github via
docker pull autenta/centos-postgresql

To run the container you can do the following:
docker run -p 5432:5432 -d -t autenta/centos-postgresql
psql -U postgres -h localhost -p 5432

安装后默认密码为空.

Dockerfile安装
可以使用它的Dockerfile(修改成了centos:7):
vim Dockerfile
=========================================代码如下:
#
FROM centos:centos7
MAINTAINER Pandy  <panyongzheng@163.com>

#Common  
#===============================================  
# INSTALL packages
RUN yum -y update    
RUN yum -y install wget tar zip unzip 

#Postgresql
#===============================================
RUN yum reinstall -y glibc-common
RUN localedef -i sv_SE -f UTF-8 sv_SE.utf8 

# install pg repo
RUN rpm -i http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm

# install server
RUN yum install -y postgresql93-server postgresql93-contrib

#初始化数据库
RUN su - postgres -c '/usr/pgsql-9.3/bin/initdb --locale=sv_SE.UTF-8 -D /var/lib/pgsql/data'

#创建表空间文件夹, 这样做也没成功
#CREATE TABLESPACE tablespacename OWNER postgres LOCATION '/var/tablespace'; 
#RUN mkdir -p "/usr/pgsql-9.3/tb_space"
#RUN chown postgres /usr/pgsql-9.3/tb_space
#RUN chmod u+x /usr/pgsql-9.3/tb_space
#RUN ls -l /usr/pgsql-9.3

# set permissions to allow logins, trust the bridge, this is the default for docker YMMV
RUN echo "host all all 0.0.0.0/0 trust" >> /var/lib/pgsql/data/pg_hba.conf

#listen on all interfaces
RUN echo "listen_addresses='*'" >> /var/lib/pgsql/data/postgresql.conf

EXPOSE 5432

VOLUME  ["/var/lib/pgsql/data"]

CMD su - postgres -c "/usr/pgsql-9.3/bin/postgres -D /var/lib/pgsql/data"



构建
docker build -t pandy/centos7-postgresql931 .
docker run -p 5431:5432 -t -d --name db -v /home/pandy/docker-resources/tb_space/:/usr/pgsql-9.3/tb_space pandy/centos7-postgresql931  //启动并挂载表空间目录
psql -U postgres -h localhost -p 5432





mysql centos6
参考:https://hub.docker.com/r/codebear4/centos6-mysql/~/dockerfile/
bootstrap.sh
#!/bin/bash
if [ ! -f /var/lib/mysql/ibdata1 ]; then
    echo "No Database(s)! Initializing..."
    echo "Running mysql_install_db"
    mysql_install_db
    echo "Starting up mysqld_safe"
    /usr/bin/mysqld_safe &
    sleep 10s
    echo "Creating user that define use ENV"
    /create_mysql_user.sh
    killall mysqld
    sleep 10s
    echo "Restarting"
fi

/usr/bin/mysqld_safe
echo "Ok."

create_mysql_user.sh
#!/bin/bash
mysql -uroot -e "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASS}'"
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_USER}'@'%' WITH GRANT OPTION"

my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


Dockerfile
FROM centos:centos6
MAINTAINER Pandy<panyongzhegn@163.com>

# Update latest packages
RUN yum -y update

# Install REMI and EPEL repositories
RUN yum -y localinstall http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
RUN yum -y localinstall http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

RUN yum --enablerepo=base clean metadata
RUN yum install -yq mysql-server
ADD my.cnf /etc/my.cnf
EXPOSE 3306
#配置mysql账户和密码
ENV MYSQL_USER root
ENV MYSQL_PASS 123456
ADD create_mysql_user.sh /create_mysql_user.sh
RUN chmod +x /create_mysql_user.sh
ADD bootstrap.sh /bootstrap
RUN chmod +x /bootstrap
ENTRYPOINT ["/bootstrap"]

docker build -t pandy/centos6-mysql .
docker run --name lamp -d -p 3307:3306 pandy/centos6-mysql




apache + php centos6
FROM centos:centos6
MAINTAINER Pandy<panyongzhegn@163.com>

# Update latest packages
RUN yum -y update

# Install REMI and EPEL repositories
RUN yum -y localinstall http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
RUN yum -y localinstall http://rpms.famillecollet.com/enterprise/remi-release-6.rpm


# apache is successfull. httpd-2.2.15-47.el6.centos.x86_64
RUN yum -y install httpd
#Apache ENV  
ENV APACHE_TIMEOUT 60  
ENV APACHE_KEEPALIVE Off  
ENV APACHE_MAXKEEPALIVEREQUESTS 100  
ENV APACHE_KEEPALIVETIMEOUT 15  
ENV APACHE_DEFAULT_LOGS_DIR logs  
ENV APACHE_SERVERADMIN root@localhost  
ENV APACHE_DEFAULT_LOGS_LEVEL warn  
  
#PHP ENV  
ENV PHP_SHORTOPENTAG Off  
ENV PHP_MEMORYLIMIT 128M  
ENV PHP_DISPLAYERROR Off
ENV PHP_TIMEZONE "UTC"

ENV APACHE_RUN_USER apache
ENV APACHE_RUN_GROUP apache
ENV APACHE_LOG_DIR /etc/httpd/logs/
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]

# php is fialed. 5.3.3-46.el6_6
RUN yum install -y php php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml php-common php-mbstring php-mcrypt php-xml
ADD www/info.php /var/www/html/

#EXPOSE 80 3306

#RUN yum install -y python-setuptools  
#RUN easy_install supervisor
#RUN supervisord --version
#ADD supervisord.conf /etc/
#CMD ["supervisord", "-n"]
#CMD ["/usr/bin/supervisord", "-n"]

docker build -t pandy/centos6-php .
docker run --name lamp -d -p 81:80 pandy/centos6-php







JAVA+Redis+Tomcat
*********************************************************************
FROM centos:centos7 
MAINTAINER Pandy  <panyongzheng@163.com>

# UPDATE
RUN yum -y update



#安装Supervisor
#===============================================
#RUN yum -y install supervisor
RUN yum install -y python-setuptools
RUN easy_install supervisor
RUN supervisord --version



#Common
#===============================================
# INSTALL packages 
RUN yum -y install wget tar zip unzip



#Java
#===============================================
#RUN yum install -y wget && wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.rpm 
#RUN rpm -Uvh jdk-7u75-linux-x64.rpm && rm jdk-7u75-linux-x64.rpm 
# set JAVA_HOME, CLASSPATH, PATH 
#ENV JAVA_HOME /usr/java/jdk1.7.0_75

COPY jdk-7u72-linux-x64.rpm /tmp/jdk-7u72-linux-x64.rpm
RUN rpm -ivh /tmp/jdk-7u72-linux-x64.rpm && rm /tmp/jdk-7u72-linux-x64.rpm
ENV JAVA_HOME /usr/java/jdk1.7.0_72
#TEST
RUN java -version
RUN javac -version



#Redis
#===============================================
# Install gcc  
#RUN yum -y install localinstall http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
#RUN yum -y localinstall http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
COPY epel-release-6-8.noarch.rpm /tmp/epel-release-6-8.noarch.rpm
RUN rpm -Uvh /tmp/epel-release-6-8.noarch.rpm && rm /tmp/epel-release-6-8.noarch.rpm
RUN yum -y install --enablerepo=epel gcc jemalloc.x86_64 jemalloc-devel.x86_64  
RUN yum -y install wget tar gcc-c++ automake autoconf libtool make
RUN yum clean all

# Install Redis.  
COPY redis-stable.tar.gz /tmp/redis-stable.tar.gz  
  
RUN \  
  cd /tmp && \  
#  wget http://download.redis.io/redis-stable.tar.gz && \ #注释掉了  
  tar xvzf redis-stable.tar.gz && \  
  cd redis-stable && \  
  make && \  
  make install && \  
  cp -f src/redis-sentinel /usr/local/bin && \  
  mkdir -p /etc/redis && \  
  cp -f *.conf /etc/redis && \  
  rm -rf /tmp/redis-stable* && \  
  sed -i 's/^\(bind .*\)$/# \1/' /etc/redis/redis.conf && \  
  sed -i 's/^\(daemonize .*\)$/# \1/' /etc/redis/redis.conf && \  
  sed -i 's/^\(dir .*\)$/# \1\ndir \/data/' /etc/redis/redis.conf && \  
  sed -i 's/^\(logfile .*\)$/# \1/' /etc/redis/redis.conf  
  
VOLUME ["/data"]  
WORKDIR /data  
EXPOSE 6379  
#CMD ["redis-server", "/etc/redis/redis.conf"]



#Tomcat
#===============================================
# TOMCAT version
ENV TOMCAT_VERSION 7.0.61

# INSTALL TOMCAT
#RUN wget -q https://archive.apache.org/dist/tomcat/tomcat-7/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz -O /tmp/tomcat7.tar.gz
COPY apache-tomcat-7.0.61.tar.gz /tmp/tomcat7.tar.gz

# UNPACK
RUN tar xzf /tmp/tomcat7.tar.gz -C /opt
RUN ln -s /opt/apache-tomcat-${TOMCAT_VERSION} /opt/tomcat
RUN rm /tmp/tomcat7.tar.gz

# REMOVE APPS 删除不必要的应用
RUN rm -rf /opt/tomcat/webapps/examples /opt/tomcat/webapps/docs 

# Add roles, 手动下载对应版本的tomcat, 然后修改tomcat-users.xml, 在进行覆盖
#ADD tomcat-users.xml /opt/tomcat/conf/

# SET CATALINE_HOME and PATH 
ENV CATALINA_HOME /opt/tomcat
ENV PATH $PATH:$CATALINA_HOME/bin


# 发布端口
EXPOSE 22 80 8080


#copy conf to image
COPY supervisord.conf /etc/supervisord.conf
#启动supervisord
CMD ["/usr/bin/supervisord"]

supervisord.conf文件
================================
[supervisord]
nodaemon=true

[program:redis]
command=redis-server /etc/redis/redis.conf

[program:tomcat]
command=/opt/tomcat/bin/startup.sh


构建:
docker build -t pandy/centos7-java7-redis3-tomcat7 .   //构建
docker run -t -i -d --name web -p 81:8080 pandy/centos7-java7-redis3-tomcat7 /bin/bash //创建, 这个不会自动启动tomcat
docker run -d --name web -p 81:8080 pandy/centos7-java7-redis3-tomcat7 /usr/bin/supervisord  //这个会自动启动tomcat
docker run -t -d --name web -p 81:8080 -v /home/pandy/docker-resources/tomcat/webapps:/opt/tomcat/webapps pandy/centos7-java7-redis3-tomcat7 /usr/bin/supervisord  //这个会自动启动tomcat, 并挂载webapps, 同时可以挂载logs, work等文件夹进去
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics