系列文章目录
【第六节】docker应用系列篇: 使用Dockerfile构建nginx
前言
提示:以下是本篇文章正文内容,下面案例可供参考
一、 准备dockerfile
1. 简单dockerFile
[root@localhost ~]# mkdir nginxroot
[root@localhost ~]# cd nginxroot
[root@localhost nginxroot]#
[root@localhost nginxroot]# echo "nginx's running" >> index.html
[root@localhost nginxroot]# ls
index.html
[root@localhost nginxroot]# cat index.html
nginx's running
[root@localhost nginxroot]# vim Dockerfile
[root@localhost nginxroot]# cat Dockerfile
FROM centos:centos7
MAINTAINER "www.kubemsb.com"
RUN yum -y install wget
RUN wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
RUN yum -y install nginx
ADD index.html /usr/share/nginx/html/
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80
CMD /usr/sbin/nginx
1.2 解决网络问题的dockerfile
上面的dockerFile如果有网络问题,无法使用yum,可以更换yum源, 使用阿里的yum源
[root@vm31 nginxroot-ali]# cat Dockerfile
FROM centos:centos7
MAINTAINER "www.kuberick.com"
RUN rm -f /etc/yum.repos.d/*
ADD ali.repo /etc/yum.repos.d/
RUN yum -y install wget
RUN wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
RUN yum -y install nginx
ADD index.html /usr/share/nginx/html/
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80
CMD /usr/sbin/nginx
ali.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
2. 构建结果:
[root@localhost nginxroot]# docker build -t centos7-nginx:v1 .
[root@vm31 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7-nginx v1 81440cec486b 7 minutes ago 757MB

最低0.47元/天 解锁文章
973

被折叠的 条评论
为什么被折叠?



