GVKun编程网logo

Docker容器内的Nginx SSL(docker容器内的进程运行在宿主机的独立的命名空间中吗)

2

对于想了解Docker容器内的NginxSSL的读者,本文将提供新的信息,我们将详细介绍docker容器内的进程运行在宿主机的独立的命名空间中吗,并且为您提供关于167dockerdocker构建ng

对于想了解Docker容器内的Nginx SSL的读者,本文将提供新的信息,我们将详细介绍docker容器内的进程运行在宿主机的独立的命名空间中吗,并且为您提供关于167 docker docker构建nginx容器系列问题 docker registry docker run docker toolbo、Docker 容器内部安装 Nginx、docker 嵌套技术 docker outside of docker 可用于一个容器内调用另一个容器内程序 跨容器调用 docker容器内获取自身容器信息、Docker学习笔记三.Docker容器安装启动(nginx,mysql,tomcat)的有价值信息。

本文目录一览:

Docker容器内的Nginx SSL(docker容器内的进程运行在宿主机的独立的命名空间中吗)

Docker容器内的Nginx SSL(docker容器内的进程运行在宿主机的独立的命名空间中吗)

我已经配置了一个Docker容器来运行Nginx并设置/ etc / nginx / sites-available / default文件,如下所示

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.php index.html index.htm; server_name example.com; location / {            try_files $uri $uri/ /index.html;    }    error_page 404 /404.html;    error_page 500 502 503 504 /50x.html;    location = /50x.html {          root /usr/share/nginx/html;    }    location ~ \.php$ {        try_files $uri =404;        fastcgi_split_path_info ^(.+\.php)(/.+)$;    fastcgi_pass unix:/var/run/php5-fpm.sock;    fastcgi_index index.php;            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;           include fastcgi_params; }}server { listen 443; root /usr/share/nginx/html; index index.php index.html index.htm; server_name example.com; ssl    on; ssl_certificate    /etc/ssl/certs/ssl-cert-snakeoil.pem; ssl_certificate_key    /etc/ssl/private/ssl-cert-snakeoil.key; location / {            try_files $uri $uri/ /index.html;    }    error_page 404 /404.html;    error_page 500 502 503 504 /50x.html;    location = /50x.html {          root /usr/share/nginx/html;    }location ~ \.php$ {        try_files $uri =404;        fastcgi_split_path_info ^(.+\.php)(/.+)$;    fastcgi_pass unix:/var/run/php5-fpm.sock;    fastcgi_index index.php;            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;           include fastcgi_params; }}

运行docker容器时,我在主机上映射了/ etc / ssl / certs和/ etc / ssl / private文件夹

docker run -dt -p 8080:443 -p 8081:80 -v /t-base/log:/var/log/nginx -v/etc/ssl/certs:/etc/ssl/certs -v /etc/ssl/private:/etc/ssl/private nginxDocker ps showsUp n minutes 0.0.0.0:8081->80/tcp 0.0.0.0:8080->443/tcp <container-name>

并且映射的/ t-base / log文件夹中的nginx错误日志文件保持为空。

docker exec -it <container-name> /bin/bash

其次是

service nginx status

刚回来并说nginx正在运行。

以上所有内容都表明一切正常。但是,我发现虽然可以浏览到

http://example.com:8080

打开默认页面

https://example.com:8081

Chrome浏览器向我显示了其默认的“悲伤笑脸”错误页面。我看不到我在做什么错。非常感谢您的帮助。

答案1

小编典典

您已互换端口。根据此命令行-p 8080:443 -p 8081:80,您应该执行以下操作:

https://example.com:8080注意,这是http 小号

http://example.com:8081

这应该工作

167 docker docker构建nginx容器系列问题 docker registry docker run docker toolbo

167 docker docker构建nginx容器系列问题 docker registry docker run docker toolbo

docker构建nginx容器系列问题


background : 最近为小伙伴们筹划docker系列的技术分享,研究了一会docker相关技术, 在此记录一下构建nginx容器时候的坑

1.nginx服务器根目录问题

docker 官方镜像提供的nginx基于debian/jessie平台,其文件结构和ubuntu中的nginx中并不相同

eg:

run一个niginx容器

<span>//80端口被占用,so...</span>
$ sudo docker run <span>-it</span><span>-p</span><span>800</span>:<span>800</span> nginx
$ sudo docker ps 

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                   NAMES
<span>1801</span>a32aab54        nginx               <span>"nginx -g ''daemon off"</span><span>2</span> minutes ago       Up <span>2</span> minutes        <span>80</span>/tcp, <span>443</span>/tcp, <span>0.0</span><span>.0</span><span>.0</span>:<span>800</span><span>-&gt;</span><span>800</span>/tcp   berserk_kare
登录后复制

进入容器内部

<span>$ </span>sudo docker exec -it <span>1801</span>a32aab54 /bin/bash
root<span>@1801a32aab54</span><span>:/</span><span># </span>
登录后复制

查看nginx目录

<span># cd /etc/nginx/</span>
conf<span>.d</span>/         koi-utf         mime<span>.types</span>      nginx<span>.conf</span>      uwsgi_params    
fastcgi_params  koi-win         modules/        scgi_params     win-utf  
登录后复制

可以看到不仅没有熟悉的 /sites-available,也没有 /sites-enabled

继续查看nginx配置

<span># cat /conf.d/default.conf</span><span>server</span> {
    listen       <span>80</span>;
    server_name  localhost;

    <span>#charset koi8-r;</span><span>#access_log  /var/log/nginx/log/host.access.log  main;</span>    location / {
        root   /usr/share/nginx/html;
        <span>index</span><span>index</span>.html <span>index</span>.htm;
    }

    <span>#error_page  404              /404.html;</span><span># redirect server error pages to the static page /50x.html</span><span>#</span>
    error_page   <span>500</span><span>502</span><span>503</span><span>504</span>  /<span>50</span>x.html;
    location = /<span>50</span>x.html {
        root   /usr/share/nginx/html;
    }
    <span>#...省略php-fpm配置,好长..</span>
}
登录后复制

根目录配置: root /usr/share/nginx/html;

测试

<span># cd /usr/share/nginx/html</span><span># touch index.html</span><span># echo "test nginx in docker" &gt;index.html</span>
登录后复制

php-fpm配置相关

'').addClass(''pre-numbering'').hide(); $(this).addClass(''has-numbering'').parent().append($numbering); for (i = 1; i '').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了167 docker docker构建nginx容器系列问题,包括了docker,nginx方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Docker 容器内部安装 Nginx

Docker 容器内部安装 Nginx

摘要: 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

用云栖社区 APP,舒服~

原文链接

docker 嵌套技术 docker outside of docker 可用于一个容器内调用另一个容器内程序 跨容器调用 docker容器内获取自身容器信息

docker 嵌套技术 docker outside of docker 可用于一个容器内调用另一个容器内程序 跨容器调用 docker容器内获取自身容器信息

环境:centos7  docker升级为最新版,

docker升级方法参考:《centos7 docker升级到最新稳定版本》centos7 docker升级到最新稳定版本_whatday的专栏-CSDN博客_centos7哪个版本稳定

以tomcat容器为例:

docker run --name web --privileged -v /etc/localtime:/etc/localtime:ro -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -d -p 8080:8080  tomcat:8.5.35

重点:

1.将宿主机 /var/run/docker.sock 文件挂载到容器,实现容器内 docker 操作宿主机 docker 的目的

2.将宿主机 /usr/bin/docker  文件挂载到容器,直接当docker客户端使用。

宿主机docker列表:

tomcat容器内docker列表:

可以看到完全一样,

此时可以在 tomcat 容器中调用 其他容器 内的程序,示例如下:

 docker exec 其他容器 /bin/bash -c 'cd /packages/detectron && python tools/train.py'

注意事项:

1.-it 有可能造成命令不执行,特别是在程序调用时,确认的确需要再加上-it

2.如果程序调用脚本,脚本中,在 -c ''中用到变量如$1,将不会传递,因为这个shell变量到了其他容器内并不存在,可用映射目录临时文件存储变量的方式来传递。

具体可参考:《docker 在容器外执行某个容器内的某个命令》docker 在容器外执行某个容器内的某个命令_whatday的专栏-CSDN博客_docker 外部执行命令

Docker学习笔记三.Docker容器安装启动(nginx,mysql,tomcat)

Docker学习笔记三.Docker容器安装启动(nginx,mysql,tomcat)

 

我自己里的Docker容器就是使用Docker镜像启动了一个单独的容器,启动之后跟镜像关系不大了(目前理解,后期再说吧)。


 

 

1.安装启动Nginx容器

#1. 用docker search Nginx 命令来查看可用版本
$ docker search Nginx
#2. 这里我们拉取官方的1.8.1版本的镜像:
$ docker pull Nginx:1.8.1

#3. 安装完成后,我们可以使用以下命令来运行 Nginx 容器:

$ docker run --name Nginx-test -p 8080:80 -d Nginx:1.8.1

#参数说明: # --name Nginx-test:容器名称。 # -p 8080:80: 端口进行映射,将本地 8080 端口映射到容器内部的 80 端口。 # -d Nginx: 设置容器在在后台一直运行。 #4. 最后可以通过浏览器可以直接访问 8080 端口的Nginx 服务


三行命令启动了Nginx程序!

 

2.将Nginx关键目录映射到本机

#首先在本机创建Nginx的一些文件存储目录
mkdir -p /root/Nginx/www /root/Nginx/logs /root/Nginx/conf

 

 

www: Nginx存储网站网页的目录

logs: Nginx日志目录

conf: Nginx配置文件目录

 

将Nginx-test容器配置文件copy到本地

docker cp Nginx-test:/etc/Nginx/Nginx.conf /root/Nginx/conf

 

删除旧的Nginx-test容器,创建新Nginx容器Nginx-test,并将www,logs,conf目录映射到本地

docker run -d -p 80:80 --name Nginx-test -v /root/Nginx/www:/usr/share/Nginx/html -v /root/Nginx/conf/Nginx.conf:/etc/Nginx/Nginx.conf -v /root/Nginx/logs:/var/log/Nginx Nginx:1.8.1

 

启动Nginx

docker start Nginx-test

 

在以后在本机/root/Nginx/www目录下创建index.html,重新访问,就成功了。

结束了!

 

 

 

 


  

安装启MysqL容器

#1. 用docker search MySQL命令来查看可用版本
$ docker search MysqL

#2. 这里我们拉取官方的最新版本的镜像:
$ docker pull MysqL:latest

#3. 安装完成后,我们可以使用以下命令来运行 Nginx 容器:

$ docker run -itd --name MysqL-test -p 3306:3306 -e MysqL_ROOT_PASSWORD=123456 MysqL  
 #参数说明:
   #  --name MysqL-test:容器名称。
   #  -p 3306:3306 :映射容器服务的 3306 端口到宿主机的 3306 端口,外部主机可以直接通过 宿主机ip:3306 访问到 MysqL 的服务。
   #  MysqL_ROOT_PASSWORD=123456:设置 MysqL 服务 root 用户的密码。

#4. 最后

 

 

 

 

 

 

 

 

 

 

 

 

 

 

、、、、

 

关于Docker容器内的Nginx SSLdocker容器内的进程运行在宿主机的独立的命名空间中吗的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于167 docker docker构建nginx容器系列问题 docker registry docker run docker toolbo、Docker 容器内部安装 Nginx、docker 嵌套技术 docker outside of docker 可用于一个容器内调用另一个容器内程序 跨容器调用 docker容器内获取自身容器信息、Docker学习笔记三.Docker容器安装启动(nginx,mysql,tomcat)等相关内容,可以在本站寻找。

本文标签: