0

I am trying to use Vault in a Spring Boot app and created the following docker-compose and vault.json files.

version: '3.8'

services:
  vault:
    container_name: vault
    image: vault
    restart: always
    environment:
      VAULT_ADDR: http://127.0.0.1:8200
    entrypoint: vault server -config=/vault.json
    ports:
      - '8200:8200'
    volumes:
      - ./volumes/logs:/vault/logs
      - ./volumes/file:/vault/file
      - ./volumes/config:/vault/config
    cap_add:
      - IPC_LOCK
{
    "backend": {
        "file": {
            "path": "/vault/file"
        }
    },
    "listener": {
        "tcp": {
            "address": "0.0.0.0:8200",
            "tls_disable": 1
        }
    },
    "ui": true,
    "disable_mlock": true
}

And keep them in the same directory and try to run the following command in this directory using bash and cmd:

docker-compose up --build

But it gives the following message and error:

[+] Running 1/1 Container vault Recreated 0.1s Attaching to vault vault | error loading configuration from vault.json: stat vault.json: no such file or directory

I tried many combination on the entrypoint: vault server -config=/vault.json line, but still the same problem. How to solve it?

Compo
  • 36,585
  • 5
  • 27
  • 39
jonathan
  • 1
  • 7

1 Answers1

0

You need to add vault.json in volume section.

volumes:
  - ./vault.json:/vault.json

Your compose file should change to this:

version: '3.8'

services:
  vault:
    container_name: vault
    image: vault
    restart: always
    environment:
      VAULT_ADDR: http://127.0.0.1:8200
    entrypoint: vault server -config=/vault.json
    ports:
      - '8200:8200'
    volumes:
      - ./volumes/logs:/vault/logs
      - ./volumes/file:/vault/file
      - ./volumes/config:/vault/config
      - ./vault.json:/vault.json
    cap_add:
      - IPC_LOCK
Xirehat
  • 1,155
  • 1
  • 8
  • 20
  • I also have this vault.json file, then what is this file? I could not understand the purpose and usage of this vault.json. Any idea? – jonathan Apr 04 '23 at 08:52
  • On the other hand, still the same error. I think entrypoint should need the file in the directory. So, any idea? – jonathan Apr 04 '23 at 09:05
  • vault.json is configuration file of vault. I tested it and got successful message. I put `docker-compose.yaml` and `vault.json` in same directory and run `docker compose up --build`. It's work – Xirehat Apr 04 '23 at 11:32
  • Sorry, but Still the same error. I also re-checked file names and copy your code. I am using Windows, I hope not related to this. – jonathan Apr 04 '23 at 12:29