docker - Docker for Mac 和 mkdir 权限
问题描述
使用 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 - 仍然得到与上面完全相同的错误。
珍惜时间 - 提前。
解决方案
db
PGDATA 所在服务状态的环境变量,/var/lib/postgresql/data/pgdata
但您在容器中安装 pgdata 卷/usr/local/var/postgres_data
。
我的猜测是,当 postgres 启动时,它正在查看环境变量并期待/var/lib/postgresql/data/pgdata
. 由于它可能不存在,它试图将其创建为无权执行此操作的 postgres 用户。
对两个变量使用相同的路径,我很确定它会修复错误。
推荐阅读
- javascript - 如何将 map() 与来自 axios 响应的数据一起使用?
- php - SQLite3 Prepared Statements 让我出错
- python - tf.distribute.Strategy.scope() 里面必须有什么?
- apache-kafka - 发件箱模式 - 我们如何防止消息中继进程生成重复消息?
- javascript - 缩放图像和标记
- ruby - 如何在 Ruby 0n 中调用不是类实例的函数
- debugging - 无法在 VSCode 中使用 gdb 进行调试
- android - onlocationChange 没有调用
- java - 通过 JNA 将击键发送到隐藏窗口
- python - 无法将_keys 发送到工具提示所涵盖的 webelement