環(huán)境:?CentOS 7 Linux 3.10.0-1160.el7.x86_64
具體要求如下:
(1)基于centos基礎(chǔ)鏡像;
(2)指定作者信息;
(3)安裝nginx服務(wù),將提供的dest目錄(提供默認(rèn)主頁(yè)index.html)傳到鏡像內(nèi),并將dest目錄內(nèi)的前端文件復(fù)制到nginx的工作目錄;
(4)暴露80端口;
(5)設(shè)置服務(wù)自啟動(dòng)。
(6)驗(yàn)證鏡像。
步驟
①創(chuàng)建項(xiàng)目目錄
②創(chuàng)建html文件
③創(chuàng)建Dockerfile
④構(gòu)建Docker 鏡像
⑤登陸到鏡像倉(cāng)庫(kù)
⑥打標(biāo)記并將nginx:v1.1鏡像推送到遠(yuǎn)程倉(cāng)庫(kù)
⑦運(yùn)行鏡像
①創(chuàng)建項(xiàng)目目錄
[root@node1 ~]# mkdir nginx
[root@node1 ~]# cd nginx
②創(chuàng)建html文件
[root@node1 ~]# cd nginx/
[root@node1 nginx]# cat index.html?
<html>
<head>
<title> node1 docker nginx demo </title>
</head>
<body>
<h1> This is Nginx - node1 </h1>
</body>
</html>
③創(chuàng)建Dockerfile
Dockerfile包含了Docker的指令。在nginx目錄下創(chuàng)建Dockerfile,文件名必須是Dockerfile。
[root@node1 nginx]# cat Dockerfile?
FROM centos:7
MAINTAINER "mysql <mysql@163.com>"? ? ? ??
RUN yum install -y ?gcc gcc-c++ ?pcre pcre-devel zlib zlib-devel openssl openssl-devel wget\
? ? && useradd -r -s /sbin/nologin nginx \
? ? && yum clean all?RUN wget http://nginx.org/download/nginx-1.16.1.tar.gz && tar -xf nginx-1.16.1.tar.gz -C /usr/local/src/
RUN cd /usr/local/src/nginx-1.16.1 \
? ? && ./configure --prefix=/apps/nginx \
? ? && make \
? ? && make install \
? ? && rm -rf /usr/local/src/nginx*?
#COPY nginx.conf /apps/nginx/conf/nginx.confWORKDIR /usr/local/src/nginx
COPY index.html /apps/nginx/html/
RUN ln -s /apps/nginx/sbin/nginx /usr/sbin/nginx?
EXPOSE 80
CMD ["/usr/sbin/nginx","-g","daemon off;"]
了解Dockerfile指令 :? ? ? ?http://t.csdn.cn/hJf7A
④構(gòu)建Docker 鏡像
[root@node1 nginx]#?docker build -t nginx:v1.1 .
……
Successfully built bc151e88c131
Successfully tagged nginx:v1.1
⑤登陸到鏡像倉(cāng)庫(kù)
[root@node1 nginx]# docker login -u admin -p Harbor12345 192.168.19.133:8081
⑥打標(biāo)記并將nginx:v1.1鏡像推送到遠(yuǎn)程倉(cāng)庫(kù)
[root@node1 nginx]# docker images
REPOSITORY ? ? ? ? ? ? ? ? ? ? ?TAG ? ? ? IMAGE ID ? ? ? CREATED ? ? ? ? ? ? SIZE
nginx ? ? ? ? ? ? ? ? ? ? ? ? ? v1.1 ? ? ?bc151e88c131 ? About an hour ago ? 347MB[root@node1 nginx]# docker tag nginx:v1.1 node1:8081/test/nginx:v1.1
[root@node1 nginx]# docker push ?node1:8081/test/nginx:v1.1
⑦運(yùn)行鏡像
[root@node1 nginx]# docker run -p 80:80 -d nginx:v1.1
068f91f7655046047cf231144e1500bf44ee75eeb3e2aaad367eabce771e9ce0
[root@node1 nginx]# curl 192.168.19.133
<html>
????????<head>
????????????????<title> node1 docker nginx demo </title>
????????</head>
????????<body>
????????????????<h1> This is Nginx - node1 </h1>
????????</body>
</html>文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-679300.html
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-679300.html
到了這里,關(guān)于編寫(xiě)Dockerfile制作Web應(yīng)用系統(tǒng)nginx鏡像,生成鏡像nginx:v1.1,并推送其到私有倉(cāng)庫(kù)。的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!