容器中基于NGINX的示例网站
我正在使用Docker并尝试使用James Turnbull的书来创建一个具有工作nginx的容器。创建并运行容器后,我尝试访问公共端口上的容器中基于NGINX的示例网站,nginx,docker,Nginx,Docker,我正在使用Docker并尝试使用James Turnbull的书来创建一个具有工作nginx的容器。创建并运行容器后,我尝试访问公共端口上的HTML页面,但我得到了403禁止的状态代码。 Dockerfile在这里: FROM ubuntu:14.04 RUN apt-get -yqq update && apt-get -yqq install nginx RUN mkdir -p /var/www/html/website ADD nginx/global.conf /e
HTML
页面,但我得到了403禁止的状态代码。
Dockerfile
在这里:
FROM ubuntu:14.04
RUN apt-get -yqq update && apt-get -yqq install nginx
RUN mkdir -p /var/www/html/website
ADD nginx/global.conf /etc/nginx/conf.d/
ADD nginx/nginx.conf /etc/nginx/
EXPOSE 80
global.conf
:
server {
listen 0.0.0.0:80;
server_name _;
root /var/www/html/website;
index index.html index.htm;
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log;
}
user www-data;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
events { }
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
}
nginx.conf
:
server {
listen 0.0.0.0:80;
server_name _;
root /var/www/html/website;
index index.html index.htm;
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log;
}
user www-data;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
events { }
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
}
我已使用上述命令运行新容器:
sudo docker run -d -p 80 --name website -v $PWD/website:/var/www/html/website:rw user007/website nginx
我怀疑nginx用户只是没有文件的读取权限。解决此问题的最简单方法是在卷上运行chmod-ra+R
。请注意,这将允许任何用户读取文件
此外,nginx用户需要对所有父目录拥有execute
权限。如果您验证端口转发是否正常运行?(这意味着错误来自主机操作系统)
也许。。您需要编辑您的命令
sudo docker run-d-p80
>sudo docker run-d-p80:80
它是由塞利努克斯引起的
与Docker一起使用卷可能会导致SELinux出现问题
完整的故事见此
使用SELinux控制容器内的进程时,需要确保卷装入容器中的任何内容都是可读的,并且可能是可写的,具体取决于用例
您可以通过运行以下命令临时发布:
su -c "setenforce 0"
自从Docker最终在Docker>1.7中合并了一个补丁以来,这变得更容易了
此修补程序在卷装载(-v)上添加了对“z”和“z”作为选项的支持
例如:
将自动执行以下操作:
chcon -Rt svirt_sandbox_file_t /var/db
访问日志中有什么?docker日志
输出对于此容器也是空的。您使用了哪个URL?你能试试curl吗?@AdrianMouat:你可以在这里查看:-rwxrwx 1 root root 121 10月31日16:00 index.html
我已经尝试过类似的方法,但错误相同。什么是主机操作系统?此外,nginx用户需要访问父目录。试着进入容器,看看你是否能以nginx用户的身份将文件cd到dir和cat中。我不得不说我不喜欢root拥有这些文件。这可能就是问题所在。它正在一个随机的公共端口上运行。问题在于特权。