【问题标题】:Docker for Mac and mkdir permisionsDocker for Mac 和 mkdir 权限
【发布时间】:2019-04-29 15:50:13
【问题描述】:

使用 docker for mac 应用程序。昨天刚刚安装了所有东西。终于让应用程序运行起来了。 但是在安装 postgis 之前我无法运行迁移。所以我放弃了postgis:11-alpine 图像的官方postgres dockerhub 图像。但是当 docker 尝试为 pg_data 卷 mkdir 时,我不断收到权限被拒绝的问题。

Dockerfile:

        version: '3'

    # Containers we are going to run
    services:
      # Our Phoenix container
      phoenix:
        # The build parameters for this container.
        build:
          # Here we define that it should build from the current directory
          context: .
        environment:
          # Variables to connect to our Postgres server
          PGUSER: postgres
          PGPASSWORD: postgres
          PGDATABASE: gametime_dev
          PGPORT: 5432
          # Hostname of our Postgres container
          PGHOST: db
        ports:
          # Mapping the port to make the Phoenix app accessible outside of the container
          - "4000:4000"
        depends_on:
          # The db container needs to be started before we start this container
          - db
          - redis

      redis:
        image: "redis:alpine"
        ports:
          - "6379:6379"
        sysctls:
          net.core.somaxconn: 1024

      db:
        # We use the predefined Postgres image
        image: mdillon/postgis:11-alpine
        environment:
          # Set user/password for Postgres
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          # Set a path where Postgres should store the data
          PGDATA: /var/lib/postgresql/data/pgdata
        restart: always
        volumes:
          - pgdata:/usr/local/var/postgres_data
    # Define the volumes
    volumes:
      pgdata:

我得到的错误:

db_1       | mkdir: can't create directory '/var/lib/postgresql/data/pgdata': Permission denied

虽然在使用 postgres(官方)图像时不会发生这种情况。我用谷歌搜索了高低。我确实读过一些关于 Docker for Mac 在它作为当前用户的本地主机用户而不是 root 用户在 VM 中创建的容器上运行命令的内容。但这对我来说没有意义 - 如果是这种情况,我该如何解决?

[额外说明:] - 我确实尝试了 :z 和 :Z - 仍然得到与上面完全相同的错误。

提前了解时间。

【问题讨论】:

    标签: docker docker-compose dockerfile docker-for-mac postgis-installation


    【解决方案1】:

    PGDATA 处于/var/lib/postgresql/data/pgdatadb 服务状态的环境变量,但您在/usr/local/var/postgres_data 的容器中安装了一个pgdata 卷。

    我的猜测是,当 postgres 启动时,它正在查看环境变量并期待 /var/lib/postgresql/data/pgdata 中的目录。由于它可能不存在,它正在尝试将其创建为无权执行此操作的 postgres 用户。

    对两个变量使用相同的路径,我很确定它会修复错误。

    【讨论】:

    • 我认为@Zeitounator 是对的,但是如果您可以为图像 mdillon/postgis:11-alpine 发布 Dockerfile,那么我们肯定会知道,因为这是容器内部的问题,与 Docker 无关适用于 Mac。
    猜你喜欢
    • 2017-10-08
    • 2012-03-22
    • 2019-08-12
    • 2011-04-15
    • 1970-01-01
    • 2016-08-15
    • 2021-07-15
    • 1970-01-01
    • 2011-12-14
    相关资源
    最近更新 更多