美文网首页
dockerfile 构建镜像应用

dockerfile 构建镜像应用

作者: 霸道ki | 来源:发表于2020-03-13 16:37 被阅读0次

1. Dockerfile指令

图片.png

2. 构建镜像

2.1 构建 nginx 镜像

mkdir /dockerfile
cd /dockerfile 
vim dockerfile-nginx

# dockfile 文件
FROM centos:7
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.16.1.tar.gz && \
    tar zxf nginx-1.16.1.tar.gz && \ 
    cd nginx-1.16.1 && \
    ./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.16.1* && \ 
    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;"] 

# 语法
Usage: docker build [OPTIONS] PATH | URL | -[flags]
Options:-t, --tag list     # 镜像名称
-f, --file string  # 指定Dockerfile文件位置

docker build -t nginx:v1 -f dockerfile-nginx .

2.1 构建 php 镜像

1.2 Dockerfile-php

FROM centos:7
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"]

docker build -t php:v1 -f dockerfile-php .

相关文章

网友评论

      本文标题:dockerfile 构建镜像应用

      本文链接:https://www.haomeiwen.com/subject/wmyrshtx.html