docker构建nginx

1.创建一个保存DOckerfile的目录

mkdir /data/nginx

2.编辑Dockerfile配置文件

vim /data/Dockerfile

From centos
RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y vim wget tree lrzsz gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop
ADD nginx-1.8.1.tar.gz /tmp/
RUN cd /tmp/nginx-1.8.1 && ./configure –prefix=/usr/local/nginx && make && make install
RUN cd /usr/local/nginx/
ADD nginx.conf /usr/local/nginx/conf/nginx.conf
RUN useradd nginx -s /sbin/nologin
RUN ln -sv /usr/local/nginx/sbin/nginx /usr/sbin/nginx
RUN echo “test nginx page” > /usr/local/nginx/html/index.html
EXPOSE 80 443
CMD [“nginx”]

3.开始构建

cp /usr/local/nginx/conf/nginx.conf .
cp /usr/local/src/nginx-1.8.1.tar.gz .
docker build -t leishujun/nginx:v4 /data/nginx/

至此,编译安装的nginx就构建完成

另外还可以yum构建Nginx,Dockerfile内容如下:

from centos
run rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
run yum install nginx -y
run echo “daemon off;” >> /etc/nginx/nginx.conf
run echo “test nginx page” > /usr/share/nginx/html/index.html
expose 80
expose 443
cmd [“nginx”,”ls”]

posted @ 2020-02-18 09:56  是烫的不是自来卷  阅读(609)  评论(0编辑  收藏  举报