skip to Main Content

I want to run echo "tools path is: $TOOLSPATH" in my docker image but make sure the variable doesn’t get expanded in my machine and sent to docker. I am not sure how to avoid variable expansion.

docker run -v `pwd`:/root -it --rm foobar echo 'tools path is: $TOOLSPATH'
> tools path is: $TOOLSPATH

docker run -v `pwd`:/root -it --rm foobar echo "tools path is: $TOOLSPATH"
> tools path is:

2

Answers


  1. There is one way to run echo $VAR inside the container and print it in your terminal. You just need to pass an interpreter too.

    docker run alpine sh -c 'echo my HOME: $HOME'
    my HOME: /root
    

    PS: I used alpine as a test. If sh doesn’t work, you can try bash instead.

    Login or Signup to reply.
  2. This might be helpful to you

    docker run -v `pwd`:/root -it --rm foobar echo "tools path is: $TOOLSPATH"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search