So I added:
# expose port 8200
EXPOSE 8200
# run a script
ENTRYPOINT ["helloworld/run.sh"]
to my Dockerfile that should have been exposed port 8200. And then I build & run it:
docker build --tag my-service .
docker run my-service --network="host"
and then here's a part of my run.sh:
cd helloworld/
export VAULT_TOKEN='token123'
export VAULT_ADDR='http://127.0.0.1:8200'
export TF_VAR_issuer_url='http://localhost:8200'
# Start Vault as a server in "dev" mode in a background and ignore its output
vault server -dev -dev-root-token-id=${VAULT_TOKEN} # &>/dev/null &
curl http://127.0.0.1:8200/v1/sys/health # https://www.vaultproject.io/api-docs/system/health
the problem is, curl command prints out:
+ curl http://127.0.0.1:8200/v1/sys/health
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (7) Failed to connect to 127.0.0.1 port 8200: Connection refused
even though locally when I run a dev server it prints out:
➜ $ curl http://127.0.0.1:8200/v1/sys/health
{"initialized":true,"sealed":false,"standby":false,"performance_standby":false,"replication_performance_mode":"disabled","replication_dr_mode":"disabled","server_time_utc":1608149576,"version":"1.5.4","cluster_name":"vault-cluster-1497c401","cluster_id":"98c78719-d8fc-2423-66bd-7e036654ba16"}
so it's probably something wrong with the way I expose the port 8200 or something.
Update: as a temporary fix, I made export LOCALHOST='host.docker.internal' and it works now but I'm wondering if there's a better solution.
curlfrom the container itself.-poption @Rezwan suggests is completely ignored with it. Conversely, "expose" as a verb is also almost meaningless in modern Docker, so don't fixate on that either. You might try launching the Vault server as a foreground process, and as the only process in its container, and running the client from somewhere else.curlcommand?