简体   繁体   English

docker-compose 不启动 postgres 并给出错误

[英]docker-compose not starting postgres and gives error

I'm really new to Docker (also postgres) and still finding my feet.我对 Docker(也是 postgres)真的很陌生,并且仍然找到了自己的脚。 I get an error and can't seem to get one of my postgres services running, although when I start it, I'm able to access pgadmin and airflow via the browser.我收到一个错误,似乎无法让我的 postgres 服务之一运行,尽管当我启动它时,我可以通过浏览器访问 pgadmin 和气流。 I think there is some sort of conflict happening but I'm not sure where.我认为发生了某种冲突,但我不确定在哪里。 I have a docker-compose.yml file that starts a few containers, as well as the postgres one in question which has the servce name db :我有一个docker-compose.yml文件,它启动了几个容器,以及有问题的 postgres 一个具有 servce 名称db

version: '3.7'
services:
    postgres:
        image: postgres:9.6
        environment:
            - POSTGRES_USER=airflow
            - POSTGRES_PASSWORD=airflow
            - POSTGRES_DB=airflow
        logging:
            options:
                max-size: 10m
                max-file: "3"

    db:
        image: postgres:13.0-alpine
        restart: always
        environment:
            POSTGRES_DB: postgres
            POSTGRES_USER: admin_user
            POSTGRES_PASSWORD: secret_password
            # PGDATA: /var/lib/postgresql/data
        volumes:
            - ./db-data:/var/lib/postgresql/data
        ports:
            - "5433:5432"
         
    pgadmin:
        image: dpage/pgadmin4:4.27
        restart: always
        environment:
            PGADMIN_DEFAULT_EMAIL: admin_user@test_email.com
            PGADMIN_DEFAULT_PASSWORD: test_password
            PGADMIN_LISTEN_PORT: 1111
        ports:
        - "1111:1111"
        volumes:
        - pgadmin-data:/var/lib/pgadmin
        links:
        - "db:pgsql-server"

    webserver:
        image: l/custom_airflow:1.5
        container_name: l_custom_airflow
        restart: always
        depends_on:
            - postgres
        environment:
            - LOAD_EX=n
            - EXECUTOR=Local
        logging:
            options:
                max-size: 10m
                max-file: "3"
        volumes:
            - ./dags:/usr/local/airflow/dags
            - ./db-data:/usr/local/airflow/db-data
            - ./pgadmin-data:/usr/local/airflow/pgadmin-data
        ports:
            - "8080:8080"
        command: webserver
        healthcheck:
            test: ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
            interval: 30s
            timeout: 30s
            retries: 3

volumes:
    db-data: 
    pgadmin-data: 

The relevant part is this:相关部分是这样的:

db:
    image: postgres:13.0-alpine
    restart: always
    environment:
        POSTGRES_DB: postgres
        POSTGRES_USER: admin_user
        POSTGRES_PASSWORD: secret_password
        # PGDATA: /var/lib/postgresql/data
    volumes:
        - ./db-data:/var/lib/postgresql/data
    ports:
        - "5433:5432"
     

[I already have two version of postgres on my local machine, and I saw that they use ports 5432 and then 5433, so it looks like the latest one goes to 5433. Similarly, I have another service (airflow) that depends on an older version of postgres to run, so I assume since that one comes first it takes 5432, and then the new postgres service I want will likely be mapped to 5433 as default - please correct me if I'm wrong] [我的本地机器上已经有两个版本的 postgres,我看到它们使用端口 5432 然后是 5433,所以看起来最新的端口是 5433。同样,我还有另一个服务(airflow),它依赖于较旧的要运行的 postgres 版本,所以我假设因为首先出现它需要 5432,然后我想要的新 postgres 服务可能会默认映射到 5433 - 如果我错了,请纠正我]

But when I run docker-compose up -d and check my containers with docker container ls -a I see that this particular container is continuously restarting.但是当我运行docker-compose up -d并使用docker container ls -a检查我的容器时,我看到这个特定的容器不断地重新启动。 I ran docker logs --tail 50 --follow --timestamps pipeline_5_db_1 (the container name for the db service) and I see the following error:我运行docker logs --tail 50 --follow --timestamps pipeline_5_db_1db服务的容器名称),我看到以下错误:

2020-10-28T08:46:29.730973000Z chmod: /var/lib/postgresql/data: Operation not permitted                                                                                                                                    2020-10-28T08:46:30.468640800Z chmod: /var/lib/postgresql/data: Operation not permitted                                                                                                                                    2020-10-28T08:46:31.048144200Z chmod: /var/lib/postgresql/data: Operation not permitted                                                                                                                                    2020-10-28T08:46:31.803571400Z chmod: /var/lib/postgresql/data: Operation not permitted                                                                                                                                    2020-10-28T08:46:32.957604600Z chmod: /var/lib/postgresql/data: Operation not permitted                                                                                                                                    2020-10-28T08:46:34.885928500Z chmod: /var/lib/postgresql/data: Operation not permitted                                                                                                                                    2020-10-28T08:46:38.479922200Z chmod: /var/lib/postgresql/data: Operation not permitted                                                                                                                                    2020-10-28T08:46:45.384436400Z chmod: /var/lib/postgresql/data: Operation not permitted                                                                                                                                    2020-10-28T08:46:58.612202300Z chmod: /var/lib/postgresql/data: Operation not permitted 

I googled the error and saw a couple of other SO posts but I can't see a clear explanation.我用谷歌搜索了错误并看到了其他一些 SO 帖子,但我看不到明确的解释。 This post and this post are a bit unclear to me (might be because I'm not so familiar), so I'm not sure how to use the responses to solve this issue. 这个帖子这个帖子对我来说有点不清楚(可能是因为我不太熟悉),所以我不确定如何使用这些回复来解决这个问题。

You've got dbdata defined as a named volume at the bottom of the compose file but you're using ./dbdata within each service which is a bind mount.您已将dbdata定义为撰写文件底部的命名卷,但您在每个绑定安装的服务中使用./dbdata You might try using the named volume instead of the shared directory in your db and webserver services, like this:您可以尝试在dbwebserver服务中使用命名卷而不是共享目录,如下所示:

    volumes:
        - db-data:/var/lib/postgresql/data

A bind mount should also work but can be troublesome if permissions on the mounted directory aren't quite right, which might be your problem.绑定挂载也应该有效,但如果挂载目录的权限不太正确,可能会很麻烦,这可能是您的问题。

The above also applies to pgadmin-data where the pgadmin service is using a named volume but webserver is using the bind mount (local directory).以上也适用于pgadmin-data ,其中pgadmin服务使用命名卷,但webserver使用绑定安装(本地目录)。 In fact, it's not clear why the webserver would need access to those data directories.事实上,不清楚为什么网络服务器需要访问这些数据目录。 Typically, a webserver would connect to the database via port 5432 (which doesn't even need to be mapped on the host).通常,网络服务器会通过端口 5432(甚至不需要映射到主机上)连接到数据库。 See for instance the bitnami/airflow docs on Docker Hub .例如参见Docker Hub 上的 bitnami/airflow 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM