dongzhiman2162 2018-05-02 12:42
浏览 47

如何安全地从容器中获取rer到docker.sock?

I'm using docker-php with nginx + php-fpm (docker-compose project). When I'm trying to run an example from the documentation:

<?php
use Docker\API\Model\ContainersCreatePostBody;
use Docker\Docker;
$docker= Docker::create();
$containerConfig = new ContainersCreatePostBody();
$containerConfig->setImage('nginx:latest');
$containerConfig->setCmd(['echo', 'I am running a command']);
$containerCreateResult = $docker->containerCreate($containerConfig);
var_dump($containerCreateResult);
exit;

and I'm getting the error:

Http \ Client \ Socket \ Exception \ ConnectionException - Permission denied

As far as I understand the problem is that user group, that php-fpm is using, does not have rw rights to docker.sock (I'm mounting it from the host on which the docker is running).

Configuration:

docker-compose:

The shell directory contains an application on yii2, that is used by docker-php.

version: '2'
services:
web:
  image: 'nginx:latest'
  container_name: web
  ports:
    - '80:80'
    - '443:443'
  volumes:
    - './:/shell'
  networks:
    - backend
    - frontend
  restart: always
php:
  build: ./docker/php/
  container_name: php
  volumes:
    - './:/shell'
    - '/var/run/docker.sock:/var/run/docker.sock'
  environment: []
  networks:
    - backend
  restart: always
networks:
frontend:
  driver: bridge
backend:
  driver: bridge

Dockerfile for php-fpm: github gist (too large file for post ~100 lines)

Docker is installed for the experiment, and so it is useless in the container php-fpm.

Software versions:

  • Docker version 1.13.1
  • docker-compose version 1.8.0
  • Kubuntu 17.10 x64

I found something similar in the Internet (one, two, three ...), the decision is to add the user, from which the application works in the container, to the group www-data.

If I assign 777 rights to docker.sock, then everything will be working, but this is a bad solution =)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮