【发布时间】:2019-03-19 14:12:31
【问题描述】:
我有以下 docker-compose 文件:
version: '3'
services:
web:
build:
context: ./django_httpd_mod_wsgi
ports:
- "8000:80"
db:
build:
context: ./postgresql
volumes:
- db-data:/var/lib/postgres/data
volumes:
db-data:
我正在使用 archlinux 构建 psotgresql 映像:
以下是我的 postgresql Dockerfile:
FROM archlinux/base
RUN yes | pacman -S postgresql
RUN mkdir /run/postgresql/
RUN chown -R postgres:postgres /run/postgresql/
USER postgres
RUN initdb -D /var/lib/postgres/data
RUN psql -c 'CREATE DATABASE btgapp;'
RUN psql -c "CREATE USER simha WITH PASSWORD 'krishna';"
RUN psql -c 'GRANT ALL PRIVILEGES ON DATABASE btgapp TO simha;'
CMD ["/usr/bin/postgres","-D","/var/lib/postgres/data"]
当我尝试这样做时:
docker-compose up
我得到错误:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/run/postgresql/.s.PGSQL.5432"?
ERROR: Service 'db' failed to build: The command '/bin/sh -c psql -c 'CREATE DATABASE dbname;'' returned a non-zero code: 2
我知道我必须在/usr/bin/postgres -D /var/lib/postgres/data启动postgresql服务器后运行psql -c CREATE DATABSE "dbname"
但我无法在 Dockerfile 中启动多个命令。那么该怎么做呢。
选项是启动脚本。但是这样就很难看到 postgres 作为单个进程运行了。
【问题讨论】:
-
您没有使用官方 postgres 图像的任何特殊原因?它在启动时支持这种类型的行为。
-
我想试试archlinux。因为我的所有网络和 redis 也使用相同的操作系统。它也将节省空间。
标签: postgresql docker docker-compose archlinux