把centos7安装的过程写成脚本
一、代码及步骤简要说明如下
#最简版的
FROM centos
#网速慢的话,设置yum源
#安装目录
RUN ["yum","install","-y","gcc","pcre","pcre-devel","make","zlib-devel"]
#创建目录
RUN ["mkdir","/root/software"]
#自动解压,从当前目录拷入
ADD nginx-1.18.0.tar.gz /root/software
#cd
WORKDIR /root/software/nginx-1.18.0
RUN ["./configure","--prefix=/usr/local/nginx"]
RUN ["make"]
RUN ["make","install"]
ENV PATH $PATH:/usr/local/nginx/sbin
RUN ["rm","-rf","/root/software"]
EXPOSE 80
WORKDIR /usr/local/nginx
CMD ["nginx","-g","daemon off;"]
二、开始操作
1.创建dockernginx文件夹
cd ..
ll
mkdir dockernginx
cd dockernginx/
如图
2.首先将nginx文件拷贝到/usr/local/docker/dockernginx/目录下
cd
cd software/
ll
cp nginx-1.19.0.tar.gz /usr/local/docker/dockernginx/
如图
3.回到之前目录下创建Dockerfile
cd /usr/local/docker/dockernginx/
vi Dockerfile
4.编辑内容如下
FROM centos
RUN ["yum","install","-y","gcc","pcre","pcre-devel","make","zlib-devel"]
RUN ["mkdir","/root/software"]
ADD nginx-1.19.0.tar.gz /root/software
WORKDIR /root/software/nginx-1.19.0
RUN ["./configure","--prefix=/usr/local/nginx"]
RUN ["make"]
RUN ["make","install"]
ENV PATH $PATH:/usr/local/nginx/sbin
RUN ["rm","-rf","/root/software"]
EXPOSE 80
WORKDIR /usr/local/nginx
CMD ["nginx","-g","daemon off;"]
5.运行
docker build -t dockernginx .
6.等待下载安装完成后,执行命令
docker run dockernginx
此处默认停止了