Dockerfile의 도커 실제 응용 프로그램과 함께 시작하기


1.Dockerfile 형식

.png를 그림


2. Dockerfile 지시

.png를 그림


3. 빌드 미러

.png를 그림


4. 건설의 Nginx, PHP, 톰캣의 기본 이미지

   전제 : .zip 파일 dockerfile와 아파치 - 톰캣-8.0.46.tar.gz을 업로드

[루트 @ localhost를 first_stage] # 압축 해제 dockerfile \ .ZIP -d Dockerfile / 
아카이브 : .ZIP dockerfile 
  Dockerfile / Dockerfile-의 nginx의 : 팽창   
  팽창이 : Dockerfile / Dockerfile - PHP는   
  팽창 : Dockerfile / Dockerfile - 바람둥이가   
  팽창 : Dockerfile은 / nginx.conf    
  팽창 : Dockerfile / php에-fpm.conf의   
  팽창 : Dockerfile / php.ini 파일

Nginx에는 기본 이미지를 구축 :

[root@localhost first_stage]# sed -i 's/1.12.2/1.15.5/g' Dockerfile-nginx
[root@localhost first_stage]# cat Dockerfile-nginx
FROM centos:7
MAINTAINER www.ctnrs.com
RUN yum install -y gcc gcc-c++ make \
    openssl-devel pcre-devel gd-devel \
    iproute net-tools telnet wget curl && \
    yum clean all && \
    rm -rf /var/cache/yum/*
RUN wget http://nginx.org/download/nginx-1.15.5.tar.gz && \
    tar zxf nginx-1.15.5.tar.gz && \
    cd nginx-1.15.5 && \
    ./configure --prefix=/usr/local/nginx \
    --with-http_ssl_module \
    --with-http_stub_status_module && \
    make -j 4 && make install && \
    rm -rf /usr/local/nginx/html/* && \
    echo "ok" >> /usr/local/nginx/html/status.html && \
    cd / && rm -rf nginx-1.15.5* && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/nginx/sbin
COPY nginx.conf /usr/local/nginx/conf/nginx.conf
WORKDIR /usr/local/nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
[root@localhost first_stage]# docker build -t  nginx:v1 -f Dockerfile-nginx .
[root@localhost first_stage]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               v1                  5595125c7c2b        4 minutes ago       396MB
centos              7                   9f38484d220f        4 months ago        202MB
[root@localhost first_stage]#

构建PHP基础镜像:

[root@localhost first_stage]# cat Dockerfile-php 
FROM centos:7
MAINTAINER www.ctnrs.com
RUN yum install epel-release -y && \
    yum install -y gcc gcc-c++ make gd-devel libxml2-devel \
    libcurl-devel libjpeg-devel libpng-devel openssl-devel \
    libmcrypt-devel libxslt-devel libtidy-devel autoconf \
    iproute net-tools telnet wget curl && \
    yum clean all && \
    rm -rf /var/cache/yum/*

RUN wget http://docs.php.net/distributions/php-5.6.36.tar.gz && \
    tar zxf php-5.6.36.tar.gz && \
    cd php-5.6.36 && \
    ./configure --prefix=/usr/local/php \
    --with-config-file-path=/usr/local/php/etc \
    --enable-fpm --enable-opcache \
    --with-mysql --with-mysqli --with-pdo-mysql \
    --with-openssl --with-zlib --with-curl --with-gd \
    --with-jpeg-dir --with-png-dir --with-freetype-dir \
    --enable-mbstring --with-mcrypt --enable-hash && \
    make -j 4 && make install && \
    cp php.ini-production /usr/local/php/etc/php.ini && \
    cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf && \
    sed -i "90a \daemonize = no" /usr/local/php/etc/php-fpm.conf && \
    mkdir /usr/local/php/log && \
    cd / && rm -rf php* && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/php/sbin
COPY php.ini /usr/local/php/etc/
COPY php-fpm.conf /usr/local/php/etc/
WORKDIR /usr/local/php
EXPOSE 9000
CMD ["php-fpm"]
[root@localhost first_stage]# docker build -t  php:v1 -f Dockerfile-php .
[root@localhost first_stage]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
php                 v1                  755346c48f2c        4 minutes ago       522MB
nginx               v1                  5595125c7c2b        22 minutes ago      396MB
centos              7                   9f38484d220f        4 months ago        202MB
[root@localhost first_stage]#

构建Tomcat基础镜像:

[root@localhost first_stage]# sed -i "s/8.0.52/8.0.46/g" Dockerfile-tomcat 
[root@localhost first_stage]# cat Dockerfile-tomcat 
FROM centos:7
MAINTAINER www.ctnrs.com

ENV VERSION=8.0.46

RUN yum install java-1.8.0-openjdk wget curl unzip iproute net-tools -y && \
    yum clean all && \
    rm -rf /var/cache/yum/*

RUN wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz && \
    tar zxf apache-tomcat-${VERSION}.tar.gz && \
    mv apache-tomcat-${VERSION} /usr/local/tomcat && \
    rm -rf apache-tomcat-${VERSION}.tar.gz /usr/local/tomcat/webapps/* && \
    mkdir /usr/local/tomcat/webapps/test && \
    "확인"> /usr/local/tomcat/webapps/test/status.html && \ 에코 
    / usr / 지방 : - ' "/ dev에 /./ urandom을 Djava.security.egd = 파일"1A JAVA_OPTS ='나오지도 -i /tomcat/bin/catalina.sh && \ 
    에선 -sf는 / usr / share /은 zoneinfo / 아시아 / 상하이의 / etc / localtime으로의 

ENV 경로 $ 경로 : / usr / 지방 / 바람둥이 / 빈 

WORKDIR / usr / 지방 / 바람둥이 

8080에 노출 
CMD [ "catalina.sh", "실행"] 
[루트 @ 로컬 호스트의 first_stage] # 고정 표시기 -t 바람둥이 구축 : V1 -f Dockerfile-바람둥이.


5. 빠른 빌드 웹 사이트 플랫폼 LNMP

.png를 그림



추천

출처blog.51cto.com/dengaosky/2426483