Docker容器内部安装Nginx

本文涉及的产品
容器服务 Serverless 版 ACK Serverless,952元额度 多规格
容器服务 Serverless 版 ACK Serverless,317元额度 多规格
容器镜像服务 ACR,镜像仓库100个 不限时长
简介: Docker容器下环境安装Nginx笔记,中途遇到些问题希望高手指教。

1、下载依赖包和Nginx

 wget http://zlib.net/zlib-1.2.11.tar.gz
 wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
wget http://nginx.org/download/nginx-1.8.0.tar.gz

2、解压缩并按照openssl开发包
[root@7e0590732abb ng]# ll
total 9060
-rw-r--r--. 1 root root 832104 Apr 21 2015 nginx-1.8.0.tar.gz
-rw-r--r--. 1 root root 5365054 May 25 13:09 openssl-1.0.2l.tar.gz
-rw-r--r--. 1 root root 409600 Jul 4 13:42 pcre-8.38.tar.gz
-rw-r--r--. 1 root root 2053336 Jan 12 2016 pcre-8.38.tar.gz.1
-rw-r--r--. 1 root root 607698 Jan 15 18:13 zlib-1.2.11.tar.gz

[root@7e0590732abb ng]# tar -zvxf openssl-1.0.2l.tar.gz
[root@7e0590732abb ng]# tar -zvxf pcre-8.38.tar.gz
[root@7e0590732abb ng]# tar zvxf zlib-1.2.11.tar.gz
[root@7e0590732abb ng]# tar -zvxf nginx-1.8.0.tar.gz
[root@7e0590732abb ng]# ll
total 8676
drwxr-xr-x. 8 1001 1001 4096 Apr 21 2015 nginx-1.8.0
-rw-r--r--. 1 root root 832104 Apr 21 2015 nginx-1.8.0.tar.gz
drwxr-xr-x. 21 root root 4096 Jul 4 13:55 openssl-1.0.2l
-rw-r--r--. 1 root root 5365054 May 25 13:09 openssl-1.0.2l.tar.gz
drwxr-xr-x. 7 1169 1169 4096 Nov 23 2015 pcre-8.38
-rw-r--r--. 1 root root 2053336 Jan 12 2016 pcre-8.38.tar.gz
drwxr-xr-x. 14 501 games 4096 Jan 15 17:36 zlib-1.2.11
-rw-r--r--. 1 root root 607698 Jan 15 18:13 zlib-1.2.11.tar.gz

安装openssl开发包:

[root@7e0590732abb include]# yum -y install openssl-devel 

3、安装make工具,后面编译安装时会用到。
[root@7e0590732abb nginx-1.8.0]# yum -y install make
configure: error: You need a C++ compiler for C++ support.
make[1]: * [/ng/pcre-8.38/Makefile] Error 1
make[1]: Leaving directory `/ng/nginx-1.8.0'
make: * [build] Error 2

4、在安装make时提示需要安装C++
[root@7e0590732abb nginx-1.8.0]# yum -y install gcc gcc-c++

5、编译安装
[root@7e0590732abb nginx-1.8.0]# ./configure --sbin-path=/ng/nginx-1.8.0/nginx --conf-path=/ng/nginx-1.8.0/nginx.conf --pid-path=/ng/nginx-1.8.0/nginx.pid --with-http_ssl_module --with-pcre=/ng/pcre-8.38 --with-zlib=/ng/zlib-1.2.11 --with-openssl=/ng/openssl-1.0.2l
checking for OS
........
............
Configuration summary

  • using PCRE library: /ng/pcre-8.38
  • using OpenSSL library: /ng/openssl-1.0.2l
  • md5: using OpenSSL library
  • sha1: using OpenSSL library
  • using zlib library: /ng/zlib-1.2.11

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/ng/nginx-1.8.0/nginx"
nginx configuration prefix: "/ng/nginx-1.8.0"
nginx configuration file: "/ng/nginx-1.8.0/nginx.conf"
nginx pid file: "/ng/nginx-1.8.0/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

[root@7e0590732abb nginx-1.8.0]# make
make -f objs/Makefile
......
.........
make[2]: Leaving directory `/ng/openssl-1.0.2l'
Operating system: x86_64-whatever-linux2
You need Perl 5.
make[1]: * [/ng/openssl-1.0.2l/.openssl/include/openssl/ssl.h] Error 1
make[1]: Leaving directory `/ng/nginx-1.8.0'
make: * [build] Error 2

[root@7e0590732abb nginx]# pwd
/usr/local/nginx
[root@7e0590732abb nginx]# cd sbin
[root@7e0590732abb sbin]# ls
nginx
[root@7e0590732abb sbin]# ./nginx
[root@7e0590732abb sbin]# ss -tnl | nginx
bash: nginx: command not found
bash: ss: command not found
[root@7e0590732abb sbin]# yum -y install netstat
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile

  • base: mirror.bit.edu.cn
  • extras: mirror.bit.edu.cn
  • updates: mirror.bit.edu.cn
    ......

..........
Complete!
[root@7e0590732abb sbin]# netstat -an | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

6、因为上面的容器在启动时没有映射端口,容器保存后映射端口并运行。

[root@docker01 ~]# docker run -it -p 80:80 --name ngx00 -v /ng:/ng c367c7a906d8 /bin/bash
[root@a4f55a7586e4 sbin]# ./nginx
[root@a4f55a7586e4 sbin]# netstat -an | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

7、使用宿主机IP+80端口访问正常
screenshot

问题:
在编译安装时仍然有报错,如果高手看到帮忙分析一下,目前还没找到解决方案。
screenshot

目录
相关文章
|
7天前
|
弹性计算 运维 持续交付
探索Docker容器化技术及其在生产环境中的应用
探索Docker容器化技术及其在生产环境中的应用
38 5
|
2天前
|
负载均衡 网络协议 开发者
掌握 Docker 网络:构建复杂的容器通信
在 Docker 容器化环境中,容器间的通信至关重要。本文详细介绍了 Docker 网络的基本概念和类型,包括桥接网络、宿主网络、覆盖网络和 Macvlan 网络等,并提供了创建、管理和配置自定义网络的实用命令。通过掌握这些知识,开发者可以构建更健壮和灵活的容器化应用,提高应用的可扩展性和安全性。
|
2天前
|
运维 Ubuntu Linux
深入理解并实践Docker容器化技术
深入理解并实践Docker容器化技术
21 6
|
8天前
|
运维 Docker 微服务
掌握 Docker Compose:简化你的多容器应用部署
在微服务架构和容器化技术普及的今天,管理多容器部署变得颇具挑战。Docker Compose 通过一个 YAML 文件定义和运行多容器应用,简化了部署和运维。本文介绍其基本概念、使用方法及优势,包括服务、项目、卷和网络等核心概念,并提供从安装到管理服务的详细步骤,助你轻松掌握 Docker Compose,提高开发效率和应用运维质量。
|
8天前
|
Cloud Native 持续交付 Docker
探索Docker容器化技术及其在软件开发中的应用
探索Docker容器化技术及其在软件开发中的应用
17 7
|
8天前
|
存储 虚拟化 开发者
深入理解Docker容器化技术
深入理解Docker容器化技术
36 6
|
5天前
|
Prometheus 监控 Cloud Native
docker安装prometheus+Granfan并监控容器
【9月更文挑战第14天】本文介绍了在Docker中安装Prometheus与Grafana并监控容器的步骤,包括创建配置文件、运行Prometheus与Grafana容器,以及在Grafana中配置数据源和创建监控仪表盘,展示了如何通过Prometheus抓取数据并利用Grafana展示容器的CPU使用率等关键指标。
|
10天前
|
持续交付 开发者 Docker
掌握 Docker:容器化技术在现代开发中的应用
Docker 是一个开源容器化平台,使开发者能够将应用程序及其依赖项封装在轻量级容器中,确保跨平台的一致性。本文介绍了 Docker 的基本概念、核心组件及优势,并展示了其在快速部署、一致性、可移植性和微服务架构中的应用。通过示例说明了 Docker 在本地开发环境搭建、服务依赖管理和 CI/CD 流程中的作用,以及多阶段构建、资源限制和网络模式等高级特性。掌握 Docker 可大幅提升开发效率和应用管理能力。
|
7天前
|
Cloud Native 持续交付 Docker
探索容器化技术Docker的奥秘
探索容器化技术Docker的奥秘
23 3
|
23天前
|
Cloud Native 持续交付 Docker
云原生之旅:Docker容器化实战指南
【8月更文挑战第29天】本文将引领你进入云原生技术的世界,以Docker容器化为切入点,深入浅出地介绍如何利用Docker进行应用的打包、部署及管理。我们将通过实际代码示例,一步步展示Docker镜像的构建过程,以及如何运行和管理这些容器。无论你是初学者还是有一定经验的开发者,都能从中获得宝贵的知识和实操经验。