【发布时间】:2019-11-18 08:08:14
【问题描述】:
我正在尝试在 DockerManually 中构建 PostgreSQL 映像,因为我需要为 docker 提供的 postgres 映像中不退出的数据库添加一些特定配置。 我写了以下dockerfile
FROM alpine:3.7
#update the OS
RUN apk update
#installing alpine software kit
RUN apk add alpine-sdk
RUN apk update \
postgresql-$PG_MAJOR-postgis-$POSTGISV \
postgresql-$PG_MAJOR-postgis-$POSTGISV-scripts \
postgresql-$PG_MAJOR-pgrouting \
postgresql-$PG_MAJOR-pgrouting-scripts \
postgresql-server-dev-$PG_MAJOR
#installing postgresql
RUN apk add postgresql
RUN apk add openrc --no-cache
RUN apk update && apk upgrade
RUN apk add --no-cache --virtual .base_deps build-base openssl-dev zlib-dev libxml2-dev wget gnupg ca-certificates
RUN apk add --no-cache readline-dev glib-lang libssl1.0 postgresql postgresql-client
RUN apk add --update binutils
RUN apk add --no-cache sudo
RUN apk --purge del .base_deps
RUN echo "postgres ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/postgres
RUN chmod 600 /etc/sudoers.d/postgres
RUN sync
#RUN /etc/init.d/postgresql start
#RUN postgres -D /usr/local/pgsql/data
EXPOSE 5432
然后我正在尝试使用交互式 shell 与 dockerfile 共进午餐
docker run -it 进程ID
然后使用以下命令来实例化数据库
initdb Database
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locales
COLLATE: C
CTYPE: C.UTF-8
MESSAGES: C
MONETARY: C
NUMERIC: C
TIME: C
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory Database ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... sh: locale: not found
2019-11-18 08:04:06.670 UTC [89] WARNING: no usable system locales were found
ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success.
然后我尝试使用以下命令对数据库进行午餐
postgres -D Database
2019-11-18 08:05:27.358 UTC [91] LOG: listening on IPv4 address "127.0.0.1", port 5432
2019-11-18 08:05:27.358 UTC [91] LOG: could not bind IPv6 address "::1": Address not available
2019-11-18 08:05:27.358 UTC [91] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-11-18 08:05:27.360 UTC [91] FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
2019-11-18 08:05:27.360 UTC [91] LOG: database system is shut down
我遇到了一些我不知道为什么的错误?任何帮助将不胜感激。
我确实切换了 docker-compose,这是文件的示例
version: "3"
services:
# Create a service named db.
db:
# Use the Docker Image postgres. This will pull the newest release.
image: "postgres:12.1-alpine"
# Give the container the name my_postgres. You can changes to something else.
container_name: "theNameOfDockerCompose"
# Setup the username, password, and database name. You can changes these values.
environment:
- POSTGRES_USER=DatabaseName
- POSTGRES_PASSWORD=Password
- POSTGRES_DB=development
# Maps port 54320 (localhost) to port 5432 on the container. You can change the ports to fix your needs.
ports:
- "5432:5432"
# Set a volume some that database is not lost after shutting down the container.
# I used the name postgres-data but you can changed it to something else.
volumes:
- ./postgres-data:/var/lib/postgresql/data
这是我现在使用的文件。 但是使用 Dockerfile,我仍然无法启用端点访问数据库。
【问题讨论】:
-
我认为这不是
bind_address问题。相反,这是两个 postmaster 在同一个端口上运行的问题。请检查ps -ef以查看 postgres 已经在哪里运行——您可能需要将port更改为Database/postgresql.conf中的另一个值(除了 5432)
标签: database postgresql docker