dockerfile创建镜像

Dockerfile创建镜像 (nginx服务)

最好使用centos 7 的镜像
在这里插入图片描述

1、需要先下载nginx的配置文件
下面的 .nginx_conf 就是下载的文件

[root@localhost ~]# wget http://www.apelearn.com/study_v2/.nginx_conf
--2020-11-07 15:35:19--  http://www.apelearn.com/study_v2/.nginx_conf
Resolving www.apelearn.com (www.apelearn.com)... 47.104.7.242
Connecting to www.apelearn.com (www.apelearn.com)|47.104.7.242|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1678 (1.6K) [application/octet-stream]
Saving to: ‘.nginx_conf’

100%[===================>] 1,678       --.-K/s   in 0s      

2020-11-07 15:35:24 (69.0 MB/s) - ‘.nginx_conf’ saved [1678/1678]

[root@localhost ~]# ls -a
.
..
anaconda-ks.cfg
.bash_history
.bash_logout
.bash_profile
.bashrc
centos-7-x86_64-minimal (1).tar.gz
.cshrc
docker-ce-17.03.0.ce-1.el7.centos.x86_64.rpm
docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm
Dockerfile
.nginx_conf
nginx_latest.tar
start.sh
.tcshrc

2、编写Dockerfile文件

[root@localhost ~]# vi Dockerfile
FROM 192.168.200.70:5000/centos
MAINTAINER liu
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
ADD http://nginx.org/download/nginx-1.8.0.tar.gz .
RUN tar zxvf nginx-1.8.0.tar.gz
RUN mkdir -p /usr/local/nginx
RUN cd nginx-1.8.0 && ./configure --prefix=/usr/local/nginx
&& make && make install
RUN rm -vf /usr/local/nginx/conf/nginx.conf
COPY .nginx_conf /usr/local/nginx/conf/nginx.conf
EXPOSE 80
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd
~
~
~
~
~
~
~
~
"Dockerfile" [New] 11L, 494C written
[root@localhost ~]# 
[root@localhost ~]# cat Dockerfile 
FROM 192.168.200.70:5000/centos7
MAINTAINER liu
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
ADD http://nginx.org/download/nginx-1.8.0.tar.gz .
RUN tar zxvf nginx-1.8.0.tar.gz
RUN mkdir -p /usr/local/nginx
RUN cd nginx-1.8.0 && ./configure --prefix=/usr/local/nginx && make && make install
RUN rm -vf /usr/local/nginx/conf/nginx.conf
COPY .nginx_conf /usr/local/nginx/conf/nginx.conf
EXPOSE 80
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd

3、创建镜像
[root@localhost ~]# docker build -t centos7_nginx . 不要忘了后面的点
4、运行此镜像

[root@localhost ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
centos_nginx                  latest              d7d2aa479322        9 seconds ago       799 MB
192.168.200.70:5000/centos7   latest              a7700d8f0394        38 minutes ago      435 MB
centos7                       latest              a7700d8f0394        38 minutes ago      435 MB
centos                        latest              0d120b6ccaa8        2 months ago        215 MB
registry                      latest              2d4f4b5309b1        4 months ago        26.2 MB
[root@localhost ~]# docker run -itd -p 8088:80 centos_nginx bash
993a6a3b6236343f3a9d3e4c1981ab694fb3811ea725650520ecccbb957a7601

5、测验
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值