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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求lingo代码和思路
    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)