DOCKERFILE编写架构(建议)

不管你使用的是这些技术中的哪一种,大多数大型应用程序都是由多个框架组成的 – 特别是微服务架构中以Docker容器来部署。即使你的应用程序使用一种语言平台和一种语言框架,应用程序部署也会从使用层次构建的结构中获益。

比如JAVA和Python

这里用Java和Python 来举例,推荐用以下架构去构建镜像

  • 操作系统层 (os)
  • 语言平台版本化 (java/python 不同的版本)
  • 添加一个应用程序框架 (spring boot、flask、django等等)
  • 最后,一个应用 (构建包含实际应用程序的镜像)

构建基础镜像

构建一个基于centos的基础镜像

FROM       centos:7.4.1708
MAINTAINER Foxchan

ENV TZ "Asia/Shanghai"
ENV TERM xterm

ADD aliyun-mirror.repo /etc/yum.repos.d/CentOS-Base.repo
ADD aliyun-epel.repo /etc/yum.repos.d/epel.repo

RUN yum install -y curl wget tar bzip2 unzip vim-enhanced passwd sudo yum-utils hostname net-tools rsync man && \
    yum install -y gcc gcc-c++ git make automake cmake patch logrotate python-devel libpng-devel libjpeg-devel && \
    yum install -y --enablerepo=epel pwgen python-pip && \
    yum clean all

RUN pip install supervisor
ADD supervisord.conf /etc/supervisord.conf

RUN mkdir -p /etc/supervisor.conf.d && \
    mkdir -p /var/log/supervisor

EXPOSE 22

ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]

构建jdk+tomcat 环境

构建有jdk和tomcat的 docker

FROM tuling/centos:7.4.1708
MAINTAINER FoxChan
#copy jdk and tomcat into image
ADD ./apache-tomcat-7.0.82.tar.gz /root
ADD ./jdk1.7.0_75 /root/jdk1.7.0_75
#set environment variable
ENV JAVA_HOME /root/jdk1.7.0_75
ENV PATH $JAVA_HOME/bin:$PATH
#define entry point which will be run first when the container starts up
ENTRYPOINT /root/apache-tomcat-7.0.82/bin/startup.sh && tail -F /root/apache-tomcat-7.0.82/logs/catalina.out

运行

docker run -d -p 8090:8080 --name tomcat tuling/tomcat:7.82

构建php-fpm环境

构建基于php-fpm的docker

FROM       tuling/centos:7.4.1708
MAINTAINER Foxchan

# Set environment variable
ENV     APP_DIR /app

RUN     yum -y swap -- remove fakesystemd -- install systemd systemd-libs && \
        yum -y install nginx php-cli php-mysql php-pear php-ldap php-mbstring php-soap php-dom php-gd php-xmlrpc php-fpm php-mcrypt && \ 
        yum clean all

ADD nginx_nginx.conf /etc/nginx/nginx.conf
ADD     nginx_default.conf /etc/nginx/conf.d/default.conf

ADD     php_www.conf /etc/php-fpm.d/www.conf
RUN     sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php.ini

RUN     mkdir -p /app && echo "<?php phpinfo(); ?>" > ${APP_DIR}/info.php

EXPOSE  80 443

ADD     supervisor_nginx.conf /etc/supervisor.conf.d/nginx.conf
ADD     supervisor_php-fpm.conf /etc/supervisor.conf.d/php-fpm.conf

ONBUILD ADD . /app
ONBUILD RUN chown -R nginx:nginx /app

运行

 docker run -d -p 9080:80 --name website tuling/php-fpm:5.4

results matching ""

    No results matching ""