简体   繁体   English

Docker 权限被拒绝以 nginx 身份运行 docker

[英]Docker Permission Denied run docker as nginx

<?php
error_reporting(-1);
ini_set('display_errors', '1');
$code = addslashes($_GET['code']);
echo shell_exec("/usr/bin/docker exec d6ebc1b02e76 perl -e \"$code\" 2>&1");

When executing this PHP script from nginx I get the following:从 nginx 执行这个 PHP 脚本时,我得到以下信息:

time="2015-07-30T23:46:03-04:00" level=fatal 
msg="Post http:///var/run/docker.sock/v1.18/containers/d6ebc1b02e76/exec: dial 
unix /var/run/docker.sock: permission denied. Are you trying to connect to a 
TLS-enabled daemon without TLS?" 

Outside of giving nginx sudo access to docker is there another solution?除了让 nginx sudo 访问 docker 之外,还有其他解决方案吗?

Extract from the doc at从文档中提取

https://docs.docker.com/installation/ubuntulinux/#optional-configurations-for-docker-on-ubuntu https://docs.docker.com/installation/ubuntulinux/#optional-configurations-for-docker-on-ubuntu

"To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group." “为了避免在使用 docker 命令时必须使用 sudo,创建一个名为 docker 的 Unix 组并向其中添加用户。当 docker 守护进程启动时,它使 Unix 套接字的所有权由 docker 组读取/写入。”

You may try that你可以试试

If you need to run docker commands as a non-root user: try like this a.如果您需要以非 root 用户身份运行 docker 命令:尝试这样Create a user 'docker' - > #adduser docker, passwd docker b.创建用户 'docker' -> #adduser docker, passwd docker b. Add a group docker -> groupadd docker c.添加组 docker -> groupadd docker c. sudo usermod -aG docker docker sudo usermod -aG docker docker

Note Add entry to /etc/sudoers %sudo All=(ALL:ALL) ALL |注意将条目添加到 /etc/sudoers %sudo All=(ALL:ALL) ALL | %sudo All=(ALL:ALL) ALL %sudo All=(ALL:ALL) ALL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM