Docker基于cenots7 制作nginx镜像

1.编写Dockerfile

FROM centos:7
MAINTAINER yang <yang@163.com>
ADD http://nginx.org/download/nginx-1.18.0.tar.gz  /usr/local/
RUN cd /usr/local/ \
	&& tar xzvf nginx-1.18.0.tar.gz -C /usr/local/ \
	&& /bin/rm -rf nginx-1.18.0.tar.gz
WORKDIR /usr/local/nginx-1.18.0
RUN yum -y install gcc pcre pcre-devel openssl openssl-devel zlib-devel gd gd-devel perl perl-ExtUtils-Embed net-tools \
	&& ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module \
	&& make && make install \
	&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
VOLUME /mnt/acs_mnt/nas/nasfiles/kb
EXPOSE 80/tcp
ENTRYPOINT ["/app/startup.sh"]
CMD ["/bin/bash"]

 2.构建镜像

docker build -t centos:2.1 .

 3.编写启动脚本startup.sh,使其工作在容器/app/目录下

#!/bin/sh
/usr/local/nginx/sbin/nginx -c /app/nginx/nginx.conf
cd /app/xxx/
chmod +x xxx     # 表示程序文件
./xxx
tail -f /dev/null

 4.查看镜像

[root@yang centosfile]# docker images
REPOSITORY                                          TAG                IMAGE ID       CREATED             SIZE
centos                                              2.1                488848f1df67   3 minutes ago       493MB

 5.push到私有镜像仓库

sudo docker tag 源镜像ID registry.cn-hangzhou.aliyuncs.com/名称空间/镜像仓库名:修改后的镜像名字
sudo docker push registry.cn-hangzhou.aliyuncs.com/xxx/xxx:centos2.1

  

posted @ 2021-04-01 16:13  西瓜君~  阅读(75)  评论(0编辑  收藏  举报