Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

HELP: Always said "bind: address already in use" when trying to start up a HA vault cluster in docker compose #109

Closed
alexwwang opened this issue Aug 31, 2018 · 12 comments

Comments

@alexwwang
Copy link

alexwwang commented Aug 31, 2018

PROBLEM:
I have stuck to this problem for several days. The log showed:
vault.server1 | Error initializing listener of type tcp: listen tcp 0.0.0.0:8200: bind: address already in use
all the time. Even if I modified listener:tcp :address, either the ip address to 127.0.0.1 or the ip of vault server, this error msg always jumped out as long as I up the docker compose.

What I've done:
I am trying to build an HA vault cluster with consul as storage backend according to this instruction: https://www.vaultproject.io/guides/operations/vault-ha-consul.html,
and this one:
https://www.hashicorp.com/resources/hashicorp-vault-administrative-guide

Below is my docker compose yml file:

version: '3.7'

services:
  consul_s1:
    container_name: consul.server1
    image: consul:latest
    command: ["agent", "-config-file=/consul/config/server_agent.json"]
    volumes:
      - ./consul/config/server1:/consul/config
      - ./consul/data/data_s1:/consul/data
    restart: unless-stopped
    ports:
      - "8090:8080"
      - "8300:8300"
      - "8500:8500"
      - "8600:8600/udp"
    networks:
      internal_net:
        ipv4_address: 172.16.238.53

  consul_s2:
    container_name: consul.server2
    image: consul:latest
    command: ["agent", "-config-file=/consul/config/server_agent.json"]
    volumes:
      - ./consul/config/server2:/consul/config
      - ./consul/data/data_s2:/consul/data
    restart: unless-stopped
    ports:
      - "8091:8080"
      - "8310:8300"
      - "8510:8500"
      - "8610:8600/udp"
    networks:
      internal_net:
        ipv4_address: 172.16.238.54

  consul_s3:
    container_name: consul.server3
    image: consul:latest
    command: ["agent", "-config-file=/consul/config/server_agent.json"]
    volumes:
      - ./consul/config/server3:/consul/config
      - ./consul/data/data_s3:/consul/data
    restart: unless-stopped
    ports:
      - "8092:8080"
      - "8320:8300"
      - "8520:8500"
      - "8620:8600/udp"
    networks:
      internal_net:
        ipv4_address: 172.16.238.55

  consul_c1:
    container_name: consul.client1
    image: consul:latest
    command: ["agent", "-config-file=/consul/config/client_agent.json"]
    volumes:
      - ./consul/config/client1:/consul/config
      - ./consul/data/data_c1:/consul/data
    restart: unless-stopped
    ports:
      - "8093:8080"
      - "8330:8300"
      - "8530:8500"
      - "8630:8600/udp"
    depends_on:
      - consul_s1
    networks:
      internal_net:
        ipv4_address: 172.16.238.201
        aliases:
          - consul-c1

  consul_c2:
    container_name: consul.client2
    image: consul:latest
    command: ["agent", "-config-file=/consul/config/client_agent.json"]
    volumes:
      - ./consul/config/client2:/consul/config
      - ./consul/data/data_c2:/consul/data
    restart: unless-stopped
    ports:
      - "8094:8080"
      - "8340:8300"
      - "8540:8500"
      - "8640:8600/udp"
    depends_on:
      - consul_s2
    networks:
      internal_net:
        ipv4_address: 172.16.238.202
        aliases:
          - consul-c2

  vault_s1:
    container_name: vault.server1
    image: vault:latest
    ports:
      - "9200:8200"
    expose:
      - "8500"
    volumes:
      - ./vault/config/server1:/vault/config
      - ./vault/logs_s1:/vault/logs
    cap_add:
      - IPC_LOCK
    command: ["server", "-config=/vault/config/vault_server.hcl", "-log-level=info"]
    depends_on:
      - consul_c1
    networks:
      internal_net:
        ipv4_address: 172.16.238.151
        aliases:
          - s1.vault

  vault_s2:
    container_name: vault.server2
    image: vault:latest
    ports:
      - "9210:8200"
    expose:
      - "8500"
    volumes:
      - ./vault/config/server2:/vault/config
      - ./vault/logs_s2:/vault/logs
    cap_add:
      - IPC_LOCK
    command: ["server", "-config=/vault/config/vault_server.hcl", "-log-level=info"]
    depends_on:
      - consul_c2
    networks:
      internal_net:
        ipv4_address: 172.16.238.152
        aliases:
          - s2.vault

networks:
  internal_net:
    driver: bridge 
    ipam:
      driver: default
      config:
        - subnet: 172.16.238.0/24

and below is one of the vault_server.hcl:

listener "tcp" {
  address         = "0.0.0.0:8200"
  cluster_address = "s1.vault:8201"
  tls_disable     = 0 
  tls_cert_file   = "/vault/config/tls/certs/server.pem"
  tls_key_file    = "/vault/config/tls/private/server-key.pem"
  tls_min_version = "tls12"
}

storage "consul" {
  address = "consul-c1:8500"
  path    = "vault/"
}

api_addr = "https://s1.vault:8200"
cluster_addr = "https://s1.vault:8201"

The consul part of configuration seems no problem and I've read document again and again to assure no 8200 port occupied in the consul part, where all default ports are used with 8080 as https port.

I will be very very appreciated if anyone could point out what's wrong with my configuration.
Thanks in advance.

@alexwwang
Copy link
Author

Update:
I try to use another port other than 8200, and I got this result:
image
I am curious why there are two listeners. The 8200 one is not set at all by myself. Where does it come from?
If I remove the address line, the error of address already in use come back again.

@alexwwang
Copy link
Author

It seems the vault would automatically load the hcl configure file in /vault/config dir, so the -config= param in command key in compose file would be redundant and cause this error.

@zen
Copy link

zen commented Nov 20, 2018

I'm struggling with similar issue, but with very basic config:
config.hcl:
storage "file" {
path = "/etc/vault/data"
}
listener "tcp" {
address = "0.0.0.0:8200"
tls_disable = 1
}

version: "3"

services:
vault:
image: vault
ports:
- "8200:8200"
volumes:
- /etc/vault/data:/vault/file
- /etc/vault/conf:/vault/config
- /etc/vault/logs:/vault/logs
cap_add:
- IPC_LOCK

vault_1_caeed44482cf | Error initializing listener of type tcp: listen tcp4 0.0.0.0:8200: bind: address already in use

Any ideas?

@alexeymarunin
Copy link

@zen
Try this

services:
  vault:
    command:
      - "server"

Seems default command (vault server -dev) conflicts config-file

@murali474
Copy link

murali474 commented Oct 11, 2019

Hi @alexeymarunin ,

Thanks for the answer .

it worked for me. vault server is started and running.

@encryptblockr
Copy link

encryptblockr commented Oct 21, 2019

@alexwwang how are you passing the certificate files into the consul and vault containers? i do not see any certs folder in your setup...also where is the vault folder in your repo https://github.com/alexwwang/HA-Vault-Consul-Docker?
i also noticed your last commit removed https but yet the docker-compose and other files reference using https still

you mind if you update this repo https://github.com/alexwwang/HA-Vault-Consul-Docker with latest working code? really interested in a working solution for your setup

thanks

@juergdrollinger
Copy link

Thanks a lot for this post!
I use ansible with an embedded config:

     env:
          VAULT_LOCAL_CONFIG: >-
             {
                  "ui": true,
                   ...

and the "-config=/vault/config" has destroyed the startup.

@alexwwang
Copy link
Author

alexwwang commented May 1, 2020 via email

@juergdrollinger
Copy link

It's solved it with the help of this description. Thanks.

@alexwwang
Copy link
Author

That's fine. Glad to hear that.

@zak905
Copy link

zak905 commented Apr 17, 2022

I solved it by removing the listener config from my custom config.hcl

@noahehall
Copy link

@alexeymarunin fix worked

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants