Skip to content
Advertisement

Docker $(pwd) and bash aliases

I’m running Docker CE in Ubuntu 16.04. I’ve created a Docker image for the polymer-cli. The idea is to be able to run polymer commands from inside disposable docker containers using bash aliases that mount the current directory, run the command and then destroy the container, like this:

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

This works perfectlty, 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 my current directory.

Anyone knows how I can solve this?

Advertisement

Answer

The problem is that, as you have used double quotes, the command substitution is being done at the time of alias declaration, not afterwards.

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 the environment variable PWD which will expand to the same value as pwd. In fact, pwd command also gets its value from PWD variable.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement