Docker基础:Dockerfile构建nginx应用

网友投稿 264 2022-10-21

Docker基础:Dockerfile构建nginx应用

1、创建Dockerfile文件

[root@docker ~]# cd /server/ [root@docker server]# mkdir file [root@docker server]# cd file/ [root@docker file]# vim Dockerfile [root@docker file]# cat Dockerfile #构建容器的基础镜像 FROM centos:centos7.7.1908 #容器镜像作者信息 MAINTAINER leoheng #添加URL下载的压缩包到当前目录 ADD . #运行必要的依赖服务组件 RUN yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel wget net-tools make #添加nginx服务运行的用户 RUN useradd -M -s /sbin/nologin nginx && yum clean all #解压编译安装过程 RUN tar -zxvf nginx-1.16.1.tar.gz RUN mkdir -p /usr/local/nginx RUN cd nginx-1.16.1 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install #软链接默认的nginx路径 RUN ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ #nginx服务运行后需要暴露的端口 EXPOSE 80 443 CMD ["nginx","-g","daemon off;"] [root@docker file]#

2、构建nginx镜像

[root@docker file]# docker build --rm -t nginx:v1 . [root@docker file]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx v1 c5324ed1af79 27 seconds ago 475MB

3、运行容器镜像

[root@docker file]# docker run -d -p 80:80 nginx:v1 [root@docker file]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES df2153d04f04 nginx:v12 "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp stupefied_kirch [root@docker file]# docker exec -it df2153d04f04 /bin/bash [root@df2153d04f04 /]# ps aux |grep nginx root 1 0.0 0.0 20556 1556 ? Ss 15:43 0:00 nginx: master process nginx -g daemon off; nginx 7 0.0 0.0 21004 1560 ? S 15:43 0:00 nginx: worker process root 23 0.0 0.0 9092 680 pts/0 S+ 15:46 0:00 grep --color=auto nginx [root@df2153d04f04 /]# exit

4、访问测试页面

[root@docker file]# curl 127.0.0.1 Welcome to nginx! Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

[root@docker file]#

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Docker进阶:部署管理redis
下一篇:SpringBoot集成Redis—使用RedisRepositories详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~