Consul、vault 和 postgres 容器无法通信

Consul、vault 和 postgres 容器无法通信

我正在尝试使用 Vault 设置 Consul,以便使用 Docker 管理 Postgres 的机密。这是我的配置

文件:

FROM python:3.6-slim

ENV VAULT_VERSION 0.11.1
ENV CONSUL_VERSION 1.2.3

RUN apt-get update \
  && apt-get install -y \
     build-essential \
     git \
     curl \
     wget \
     vim \
     net-tools \
     iputils-ping \
     dnsutils \
     zip \
     unzip \
  && wget -O /tmp/vault.zip "https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip" \
  && unzip -d /bin /tmp/vault.zip \
  && chmod 755 /bin/vault \
  && rm /tmp/vault.zip \
  && wget -O /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" \
  && unzip -d /bin /tmp/consul.zip \
  && chmod 755 /bin/consul \
  && rm /tmp/consul.zip \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*

docker-compose.yml:

version: '3.6'

services:
  consul:
  container_name: consul.server
  command: agent -server -bind 0.0.0.0 -client 0.0.0.0 -bootstrap-expect=1
  image: consul:latest
  volumes:
    - ./config/consul/config:/consul/config
  ports:
    - "9300:9300"
    - "9500:9500"
    - "9600:9600/udp"
  networks:
    - consul_network

vault:
  container_name: vault.server
  image: vault
  ports:
    - "9200:8200"
  cap_add:
    - IPC_LOCK
  depends_on:
    - consul
  environment:
    - VAULT_LOCAL_CONFIG={"backend":{"consul":{"address":"${LOCAL_IP}:9500","advertise_addr":"http://${LOCAL_IP}", "path":"vault/"}},"listener":{"tcp":{"address":"0.0.0.0:8200","tls_disable":1}}}
  command: server
  networks:
    - consul_network

db:
  image: postgres:10.5-alpine
  volumes:
    - postgres_data:/var/lib/postgresql/data/
  environment:
    - CONSUL_HTTP_ADDR=${LOCAL_IP}:9500
    - VAULT_ADDR=http://${LOCAL_IP}:9200
  networks:
    - consul_network
    - database_network

networks:
  consul_network:
    driver: bridge
  database_network:
    driver: bridge

volumes:
  postgres_data:

而且我还将 LOCAL_IP 保存在 .env 文件中:

LOCAL_IP=10.0.2.15

(我在 Vagrant 机器上开发,因此有这个地址)。我关注的是这个教程并且我假设 db 容器应该可以访问 consule.server 和 vault.server,但事实并非如此。(?)

其次,我连接到了 vault.server,并尝试获取 vault 状态,它响应了

Error checking seal status: Get https://127.0.0.1:8200/v1/sys/seal-status: http: server gave HTTP response to HTTPS client

我刚刚开始学习 Docker,坦率地说,我甚至不知道从哪里开始寻找答案,所以如果有人能给我指导,我将不胜感激。

干杯。

答案1

环境VAULT_ADDR变量需要设置为http://127.0.0.1:8200

当正常启动vault服务器时,如果禁用 TLS 运行时,您会在输出中看到以下内容:

You may need to set the following environment variable:

    $ export VAULT_ADDR='http://127.0.0.1:8200'

相关内容