Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker $(pwd) and bash aliases

Tags:

linux

bash

docker

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?

like image 447
Federico Resnizky Avatar asked Oct 24 '25 21:10

Federico Resnizky


1 Answers

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 the pwd command substitution, $(pwd) you can use the environment variable PWD expansion, $PWD, which will expand to the same value. In fact, pwd command also gets its value from the PWD variable.

like image 125
heemayl Avatar answered Oct 27 '25 12:10

heemayl