基于docker镜像centos:7 镜像制作自定义的centos及tomcat/php/nginx镜像

基于 centos:7 镜像制作自定义mycentos:v1
# 交互式运行centos:7
# docker run -it --name=mycentos

# 在运行的mycentos容器中修改网络
# vi /etc/profile

export http_proxy=http://10.11.0.150:808
export https_proxy="https://10.11.0.150:808"
export ftp_proxy=http://10.11.0.150:808
export socks_proxy="socks://10.11.0.150:808/"
export http_proxy=http://10.11.0.150:808
export https_proxy=https://10.11.0.150:808

# echo "proxy=http://10.11.0.150:808" >> /etc/yum.conf
# source /etc/profile
# 替换yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

# 安装常用工具
yum install -y iproute net-tools telnet wget curl tree iftop htop iotop lrzsz

# wget命令代理
[root@node03 ~]# cat ~/.wgetrc
http_proxy = http://10.11.0.150:808
ftp_proxy = http://10.11.0.150:808

# 提交镜像为 mycentos:v1
# docker commit mycentos mycentos:v1

 

1.编写nginx1.15.5的dockerfile

# cat Dockerfile

FROM mycentos:v1
LABEL maintainer www.chinasoft.com
RUN echo "proxy=http://10.11.0.150:808" >> /etc/yum.conf && \
    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/*

COPY nginx-1.15.5.tar.gz /
RUN 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* && \
    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;"]


2.nginx配置文件和Dockerfile

# cat nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;
    gzip  on;
    server {
        listen       80;
        server_name  localhost;
        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page  404              /404.html;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

# 编译镜像为nginx:v1
# docker build -t . nginx:v1


编译安装php

获取php5.6.36的源码包:http://mirrors.sohu.com/php/php-5.6.36.tar.gz
在官网找的zip包解压后压缩成.tar.gz不行,没有configure命令
1.编写 Dockfile

FROM mycentos:v2
LABEL maintainer www.chinasoft.com
RUN source /etc/profile && \
    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/*

COPY php-5.6.36.tar.gz /
RUN tar xf 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"]

编译安装tomcat

下载地址:https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.43/bin/apache-tomcat-8.5.43.tar.gz

# 编写Dockerfile

FROM mycentos:v2
LABEL maintainer www.chinasoft.com

ENV VERSION=8.5.43

RUN source /etc/profile && \
        yum install java-1.8.0-openjdk wget curl unzip iproute net-tools -y && \
    yum clean all && \
    rm -rf /var/cache/yum/*
COPY apache-tomcat-${VERSION}.tar.gz /
RUN source /etc/profile && \
    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 && \
    echo "ok" > /usr/local/tomcat/webapps/test/status.html && \
    sed -i '1a JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom"' /usr/local/tomcat/bin/catalina.sh && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/tomcat/bin

WORKDIR /usr/local/tomcat

EXPOSE 8080
CMD ["catalina.sh", "run"]

 

posted @ 2021-08-10 14:11  reblue520  阅读(178)  评论(0编辑  收藏  举报