如何将本地 postgreSQL 连接到 docker(CVAT)

如何将本地 postgreSQL 连接到 docker(CVAT)

我正在尝试将本地 postgreSQL 服务器(数据库名称 = cvat_lcl)连接到使用 docker-compose 创建的容器:连续可变功率放大器。我可以使用本地 pgAdmin 读取容器内托管的普通数据库(在端口 5444 上),但我部署的最终目标是运行本地版本的 postgresql 并让 CVAT 容器连接到该数据库而不是内置数据库。我是网络方面的新手,所以不太确定从哪里开始。

我目前所做的:

pg_hba.conf

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all             all             172.17.0.0/16           md5

postgres.conf

# - Connection Settings -

listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5433                             # (change requires restart)

ifconfig -a

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:c0ff:fe03:86ac  prefixlen 64  scopeid 0x20<link>
        ether 02:42:c0:03:86:ac  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4372  bytes 873445 (873.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker-compose.yml

version: '3.3'

services:
  cvat_db:
    container_name: cvat_db
    image: postgres:10-alpine
    restart: always
    environment:
      POSTGRES_USER: root
      POSTGRES_DB: cvat
      POSTGRES_HOST_AUTH_METHOD: trust
    volumes:
      - cvat_db:/var/lib/postgresql/data
    networks:
      - cvat
    ports:
      - "5444:5432"

  cvat_redis:
    container_name: cvat_redis
    image: redis:4.0-alpine
    restart: always
    networks:
      - cvat
      
  cvat:
    container_name: cvat
    image: openvino/cvat_server
    restart: always
    depends_on:
      - cvat_redis
      - cvat_db
    environment:
      DJANGO_MODWSGI_EXTRA_ARGS: ''
      ALLOWED_HOSTS: '*'
      CVAT_REDIS_HOST: 'cvat_redis'
      CVAT_POSTGRES_HOST: 'cvat_db'
      ADAPTIVE_AUTO_ANNOTATION: 'false'
    labels:
      - traefik.enable=true
      - traefik.http.services.cvat.loadbalancer.server.port=8080
      - traefik.http.routers.cvat.rule=Host(`${CVAT_HOST:-localhost}`) &&
          PathPrefix(`/api/`, `/git/`, `/opencv/`, `/analytics/`, `/static/`, `/admin`, `/documentation/`, `/django-rq`)
      - traefik.http.routers.cvat.entrypoints=web
    volumes:
      - cvat_data:/home/django/data
      - cvat_keys:/home/django/keys
      - cvat_logs:/home/django/logs
    networks:
      - cvat

  cvat_ui:
    container_name: cvat_ui
    image: openvino/cvat_ui
    restart: always
    depends_on:
      - cvat
    labels:
      - traefik.enable=true
      - traefik.http.services.cvat-ui.loadbalancer.server.port=80
      - traefik.http.routers.cvat-ui.rule=Host(`${CVAT_HOST:-localhost}`)
      - traefik.http.routers.cvat-ui.entrypoints=web
    networks:
      - cvat

  traefik:
    image: traefik:v2.4
    container_name: traefik
    command:
      - "--providers.docker.exposedByDefault=false"
      - "--providers.docker.network=cvat"
      - "--entryPoints.web.address=:8999"
    # Uncomment to get Traefik dashboard
    #   - "--entryPoints.dashboard.address=:8090"
    #   - "--api.dashboard=true"
    # labels:
    #   - traefik.enable=true
    #   - traefik.http.routers.dashboard.entrypoints=dashboard
    #   - traefik.http.routers.dashboard.service=api@internal
    #   - traefik.http.routers.dashboard.rule=Host(`${CVAT_HOST:-localhost}`)
    ports:
      - 8999:8999
      - 8090:8090
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - cvat

volumes:
  cvat_db:
  cvat_data:
  cvat_keys:
  cvat_logs:

networks:
  cvat:

总结一下——目标是连接到伐木场CVAT 容器中的数据库(在本地主机上)。CVAT 当前在 Linux 20.04 LTS 上运行。在此先感谢您的帮助。

相关内容