【问题标题】:Extending postgres image using dockerfile with POSTGRES_PASSWORD使用带有 POSTGRES_PASSWORD 的 dockerfile 扩展 postgres 图像
【发布时间】:2019-04-14 11:07:39
【问题描述】:

我正在使用参数 POSTGRES_PASSWORD=postgres 扩展 postgres 映像,这样我的派生容器就已经有了使用 docker build 和 dockerfile 的默认密码。

每当我从我从 postgres 制作的派生图像的容器上运行 psql -U postgres 时,我都会得到:

could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

在我的 DockerFile 我有:

ARG POSTGRES_PASSWORD=postgres
FROM postgres:alpine

RUN apk add --update nodejs
RUN apk add --update npm
RUN apk add --update erlang
RUN apk add --update elixir

CMD ["/bin/bash"]

然后我跑了

docker build -t myImage .
docker run --name sample -d -it myImage
docker exec -it sample bash

我想在 sample 容器上运行 psql -U postgres(图像扩展自 postgres)。

【问题讨论】:

  • 这看起来就像你在寻找像 Docker Compose 这样的编排系统,而不是试图在 Dockerfile 中修复这些东西。运行 shell 而不是启动数据库的 CMD 设置将是您的错误的直接原因。
  • @DavidMaze 制作一个运行 elixir 和 postgres 的图像是不可能的?我应该使用 docker compose 来连接 postgres 镜像和 elixir 镜像吗?
  • 是的,您绝对应该在单独的容器中运行您的数据库和应用程序。

标签: postgresql docker dockerfile


【解决方案1】:

尝试用ENV POSTGRES_PASSWORD postgres替换ARG POSTGRES_PASSWORD=postgres

postgres docker 镜像文档声明这个参数是一个环境变量,所以这可能会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    相关资源
    最近更新 更多