使用dockerfile安装nginx
[root@server3 ~]# cd /opt/
[root@server3 opt]# mkdir nginx
[root@server3 opt]# cd nginx/
[root@server3 nginx]# vi Dockerfile
FROM centos:7 #基于基础镜像
MAINTAINER this is nginx #用户信息
RUN yum -y update # 添加环境包
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
RUN useradd -M -s /sbin/nologin nginx
ADD nginx-1.12.2.tar.gz /usr/local/src 下载nginx软件包
WORKDIR /usr/local/src
WORKDIR nginx-1.12.2 #指定工作目录
RUN ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module && make && make install
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80 #指定http和httpd端口
EXPOSE 443
RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf
ADD run.sh /run.sh #添加宿主机中run.sh到容器中
RUN chmod 755 /run.sh
CMD ["/run.sh"]
[root@server3 nginx]# vi run.sh
#!/bin/bash
/usr/local/nginx/sbin/nginx
添加nginx压缩包
[root@server3 nginx]# docker build -t nginx:new . #创建新镜像
[root@server3 nginx]# docker run -d -P nginx:new
[root@server3 nginx]# docker ps -a
浏览器上测试
20.0.0.13:49161