Php无法在docker中写入文件

时间:2018-05-02 10:49:49

标签: php docker docker-compose symfony-3.4

我正在使用docker运行Symfony 3.4应用程序,我需要上传文件并将其保存到/ web / files。当我试图这样做时,我得到一个错误:

Unable to create the "/home/docker/web/files/" directory

请注意,我在cocker compose中将目录安装为读写:

version: '2'
services:  

  front:
    image: nginx
    ports:
      - "81:80"
    links:
      - "engine:engine"
      - "db:db"
    volumes:
      - ".:/home/docker:ro"
      - "./docker/front/default.conf:/etc/nginx/conf.d/default.conf:ro"

  engine:
    build: ./docker/engine/
    volumes:
      - ".:/home/docker:rw"
      - "./docker/engine/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
    links:
      - "db:db"
    working_dir: "/home/docker"

  db:
    image: camptocamp/postgres:9.6
    ports:
      - "5433:5432"
    environment:
      - "POSTGRES_DB=pfe"
      - "POSTGRES_PASSWORD=admin"
      - "POSTGRES_USER=admin"
      - "PGDATA=/var/lib/postgresql/data/pgdata"

我甚至在/ web中创建了目录文件,但它无法正常工作!

1 个答案:

答案 0 :(得分:0)

我为我的文件创建了一个单独的容器,并将其基于apache映像。然后我用volumes_from键将它传递给我的php。尝试这样的东西:

services:
    apache:
        build: ./build/httpd
        links:
            - php
        ports:
            - 80:80
            - 443:443
        volumes_from:
            - app

    php:
        build: ./build/php
        ports:
            - 9000
            - 9001
        volumes_from:
            - app
        links:
            - mariadb
            - mail

    app:
        image: httpd:latest
        volumes:
            - ./:/var/www/html
        command: "echo true"