0

I want my alias to pick up variables that I pass in commandLine:

For example, startdocker 004 should execute the following

docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar:004

(004 is the tag I am passing in commandLine).

I tried the following in my .bashrc (sourced after the change).

alias startdocker='function dockerStartTag(){ echo "docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar: $1";};dockerStartTag'

when I run startdocker 004, It is not picking up 004. It is empty and hence defaults to "latest" by docker.

what is the correct way to do it? what am I doing wrong?

Thanks

EDIT

I don't want to echo but execute the command.

The correct answer is provided below

brain storm
  • 30,124
  • 69
  • 225
  • 393
  • Possible duplicate of [Make bash alias that takes parameter?](http://stackoverflow.com/questions/7131670/make-bash-alias-that-takes-parameter) – Benjamin W. Jan 08 '16 at 20:40

1 Answers1

2

There's no reason to put a function inside an alias. Just do

function startdocker(){ echo "docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar: $1"; }

This now works on my system:

$ startdocker 004
docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar: 004

And to actually run it, we just need:

function startdocker(){ docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar: $1; }
chrisaycock
  • 36,470
  • 14
  • 88
  • 125