Docker $ (pwd) and bash aliases

I am running Docker CE on Ubuntu 16.04. I have created a Docker image for the polymer cli. The idea is to be able to run commands from within containers to dock containers using bash aliases that mount the current directory, run the command, and then destroy the container, for example:

docker run --rm -it -v $(pwd):/home/node/app -u node fresnizky/polymer-cli polymer

      

This works fine, but if I create a bash alias for this command:

alias polymer="docker run --rm -it -v $(pwd):/home/node/app -u node fresnizky/polymer-cli polymer "

      

Then $ (pwd) points to my home directory instead of the current directory.

Does anyone know how I can solve this?

+3


source to share


1 answer


The problem is that because you used double quotes, command substitution is done at the time of declaration alias

, not later.

Use single quotes:



alias polymer='docker run --rm -it -v $(pwd):/home/node/app -u node fresnizky/polymer-cli polymer'

      

Also, instead of using command substitution, $(pwd)

you can use an environment variable PWD

that will expand to the same value as PWD

. In fact, the command PWD

also gets its value from the variable PWD

.

+3


source







All Articles