1

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.

4
  • 1
    You need to use -p parameter in docker run command. expose in Dockerfile only exposes port to docker container but u are using host port.. for that u need to expose port using -p paramter . try docker run my-service -p 8200:8200 --network="host"
    – Rezwan
    Dec 16, 2020 at 20:36
  • Hmm, let me try that. Just to make sure, I do want to run that curl from the container itself.
    – Serge Vu
    Dec 16, 2020 at 21:37
  • You probably don't want host networking. Among other things, the -p option @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.
    – David Maze
    Dec 17, 2020 at 0:33
  • I wonder if the Vault server is just not up yet - have you tried adding a wait of a few seconds into your script between starting the server and the curl command?
    – lxop
    Dec 22, 2020 at 4:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.