dockerized postgres-锁定文件“ postmaster.pid”为空

时间:2019-04-19 22:26:31

标签: postgresql docker

我在使用官方Postgres码头工人镜像时遇到问题,这在这台机器上从未发生过。 我正在通过docker-compose使用它,但是在运行docker-compose up时,db容器无法启动,这是错误消息:

db_1         | 2019-04-19 22:20:27.180 UTC [1] FATAL:  lock file "postmaster.pid" is empty
db_1         | 2019-04-19 22:20:27.180 UTC [1] HINT:  Either another server is starting, or the lock file is the remnant of a previous server startup crash.

我尝试了几次删除图像,以便将其重新拉出,但尚未解决问题。

我正在使用Docker for Mac 2.0.0.3(31259)

这是docker-compose.yml

version: '2'
services:
  web:
    build: .
    entrypoint: sh -c "python3 /var/www/my_project/manage.py migrate --noinput &&
                python3 /var/www/my_project/manage.py runserver 0.0.0.0:8000"
    restart: on-failure
    ports:
      - "9001:8000"
    volumes:
      - .:/var/www/my_project
    depends_on:
    - db
    env_file:
      - ./.env
    environment:
      - DB_SERVER=db
      - DB_NAME=postgres
      - DB_USER=postgres
  db:
    ports:
        - "9432:5432"
    image: postgres
    volumes:
      - database:/var/lib/postgresql
volumes:
  database:

对此有任何帮助吗?

1 个答案:

答案 0 :(得分:0)

您可以尝试从容器安装的卷中手动删除pid文件。像这样:

搜索音量:

docker inspect container-name

搜索存储卷的目录:

...
"Mounts": [
  {
    "Type": "volume",
    "Name": "9009b4e54686dc36f797a15fd8fc09213f3e8949583b823525881c010f2fe347",
    "Source": "/var/lib/docker/volumes/9009b4e54686dc36f797a15fd8fc09213f3e8949583b823525881c010f2fe347/_data",

现在删除pid文件:

rm /var/lib/docker/volumes/9009b4e54686dc36f797a15fd8fc09213f3e8949583b823525881c010f2fe347/_data/

之后,您可能会收到以下错误消息:

lock file "/var/run/postgresql/.s.PGSQL.5432.lock" is empty

这可以通过用包含数字的文件覆盖该文件来解决:

echo 12345 > bla
docker cp bla container-name:/var/run/postgresql/.s.PGSQL.5432.lock
docker restart container-name