How to run Consul on a docker with the source data of a key-value pair?

I am trying to start a Consul server on a docker container and use it as a configuration server for a SpringBoot cloud application. For this, I want to have pre-configured data (Key-Value pairs) in Consul.

My current configuration in the docker-compose.yml file is:

  consul:
    image: "progrium/consul:latest"
    container_name: "consul"
    ports:
      - '9330:8300'
      - '9400:8400'
      - '9500:8500'
      - '9600:53'
    command: "-server -bootstrap -ui-dir /ui"

Is there a way to pre-populate key-value pairs?

+4
source share
1 answer

To write

Compose "", , . A docker-compose-init.yml , , . consul.

docker-compose up -d
docker-compose -f docker-compose-init.yml run consul_init

Image Build

RUN . , , , RUN.

FROM progrium/consul:latest
RUN set -uex; \
    consul agent -server --bootstrap -data-dir /consul/data & \ 
    let "timeout = $(date +%s) + 15"; \
    while ! curl -f -s http://localhost:8500/v1/status/leader | grep "[0-9]:[0-9]"; do\
      if [ $(date +%s) -gt $timeout ]; then echo "timeout"; exit 1; fi; \
      sleep 1; \
    done; \
    consul kv put somekey somevalue;

script . , , , mysql/postgres/mongo.

FROM progrium/consul:latest
ENTRYPOINT my-entrypoint.sh

script , , , .

0

Source: https://habr.com/ru/post/1675567/


All Articles