Home > Software design >  How to use cat command inside docker container bash
How to use cat command inside docker container bash

Time:03-30

Tried & not working

command : [bash -c "curl -k https://restapihost:port --header \"Authorization: Basic $(cat /run/secrets/my_external_secret)\""]

But this works and calls the API with correct token value.

command : [bash -c "curl -k https://restapihost:port --header \"Authorization: Basic ActualTokenValue\""]

How to add header token via cat docker secret with bash command? How can i get the

CodePudding user response:

This command works. This is simply bash stuff, it doesn't matter if it is in a container.

What the problem may be?

  1. Check the file actually exists, and contains the secret. Check for newlines, empty lines, etc. It should have just the token with no new lines
  2. Permissions issue. What's the permissions on the file? Verify the user inside the container has access to read it

If those 2 items are checked - this needs to work. If the problem still persist, try to get us some more information - use curl -v to get verbose output. This will include the headers and you would see what value is being used.

CodePudding user response:

Remove square brackets around bash:

command 
  bash -c "curl -k https://restapihost:port --header \"Authorization: Basic $(cat /run/secrets/my_external_secret)\""

Because writing using brackets you will get a docker command like

CMD [bash -c "curl -k https://restapihost:port --header \"Authorization: Basic $(cat /run/secrets/my_external_secret)\""]

and in the above case docker doesn't substitute variables.

Instead you need:

CMD bash -c "curl -k https://restapihost:port --header \"Authorization: Basic $(cat /run/secrets/my_external_secret)\""
  • Related