【第六节Dockerfile项目实例】亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述第六节Dockerfile项目实例相关的知识,希望能为你提供帮助。
实例一 构建自己的CentOS镜像
# This is my centos build
# 基础镜像
FROM centos:centos7
# 镜像作者信息
MAINTAINER xcc< xuechuchao@163.com>
# 自定义环境变量MYPATH
ENV MYPATH /usr/local
# 工作目录
WORKDIR $MYPATH
#添加阿里镜像提高下载速度
#ADD CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo
# 更新
RUN yum -y update
# 安装vim
RUN yum install -y vim
# 安装net-tools
RUN yum install -y net-tools
# 暴露80端口
EXPOSE 80
# 输出自定义环境变量
CMD echo $MYPATH
# 输出end
CMD echo "----end----"
CMD /bin/bash
实例二 构建一个nginx镜像
# create nginx container
FROM centos:centos7
# 安装基础管理命令
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/*
# 下载源码nginx包并编译安装
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.12.2* \\
& & 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#拷贝项目nginx配置
#设置工作目录
WORKDIR /usr/local/nginx
#指定端口
EXPOSE 80
CMD ["nginx","-g","daemon off; "]
实例三 mysql
实例四 Tomcat
实例五 php
FROM centos:centos7
LABEL maintainer www.chenleilei.net
RUN yum install -y curl
RUN curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo & & \\
yum clean all
RUN yum remove oniguruma-devel -y
RUN yum remove oniguruma -y
RUN rpm -ivh https://www.chenleilei.net/soft/docker/oniguruma-6.7.0-1.el7.x86_64.rpm
RUN rpm -ivh https://www.chenleilei.net/soft/docker/oniguruma-devel-6.7.0-1.el7.x86_64.rpm
RUN yum install -y cmake pcre pcre-devel openssl openssl-devel gd-devel \\
zlib-devel gcc gcc-c++ net-tools iproute telnet wget curl \\
wget vim libxml2 libxml2-devel openssl openssl-devel libjpeg-turbo \\
libjpeg-turbo-devel libpng-devel libpng freetype-devel freetype icu \\
libicu-devel libicu libmcrypt libmcrypt-devel libxslt libxslt-develphp-mysql libsqlite3x-devel & & \\
rm -rf /var/cache/yum/*
WORKDIR /
RUN useradd www -u 1200 -M -s /sbin/nologin & & mkdir -p /usr/local/nginx/html & & chown -R www.www /usr/local/nginx/html & & chmod -R 755 /usr/local/nginx/html
RUN wget https://www.chenleilei.net/soft/php-7.4.3.tar.gz
RUN tar xf php-7.4.3.tar.gz
WORKDIR php-7.4.3
RUN ./configure --prefix=/usr/local/php-7.4.3 \\
--with-config-file-path=/usr/local/php-7.4.3/etc \\
--with-config-file-scan-dir=/usr/local/php-7.4.3/conf.d \\
--enable-fpm --with-fpm-user=www \\
--with-fpm-group=www \\
--with-mysqli=mysqlnd \\
--with-pdo-mysql=mysqlnd \\
--with-iconv-dir \\
--with-zlib \\
--enable-xml \\
--disable-rpath \\
--enable-bcmath \\
--enable-shmop \\
--enable-sysvsem \\
--enable-inline-optimization \\
--enable-mbregex \\
--enable-mbstring \\
--enable-ftp \\
--with-openssl \\
--with-mhash \\
--enable-pcntl \\
--enable-sockets \\
--with-xmlrpc \\
--enable-soap \\
--with-gettext \\
--disable-fileinfo \\
--enable-opcache \\
--enable-intl \\
--with-xsl
RUN make -j 4 & & make install
RUN cp ./sapi/fpm/php-fpm.conf /usr/local/php-7.4.3/etc/php-fpm.conf & & \\
cp /php-7.4.3/php.ini-production /usr/local/php-7.4.3/etc/php.ini & & \\
cp /usr/local/php-7.4.3/etc/php-fpm.d/www.conf.default /usr/local/php-7.4.3/etc/php-fpm.d/www.conf & & \\
sed-i"s#127.0.0.1:9000#0.0.0.0:9000#g" /usr/local/php-7.4.3/etc/php-fpm.d/www.conf & & \\
sed -in 99idaemonize = yes /usr/local/php-7.4.3/etc/php-fpm.conf & & \\
cp /php-7.4.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm & & \\
chmod a+x /etc/init.d/php-fpm
WORKDIR /
RUN rm -rf /php-7.4.3.tar.gz
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
CMD /usr/local/php-7.4.3/sbin/php-fpm -F
EXPOSE 9000
推荐阅读
- XML中 元素和属性比较
- 如何删除win10的windows.old
- 手把手教你利用Win7系统快速搭建属于自己的网站
- autofs按需挂载nfs文件系统
- oeasy教您玩转vim - 91 - # vim脚本编程展望
- mysql 迁移命令及问题汇总
- 容器端口映射
- 分类保存与实时同步共享文件夹使用说明
- LINUX下载编译ncurses