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

1

1 Answer 1

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; }
Sign up to request clarification or add additional context in comments.

4 Comments

oh may be I did not express correctly. I want that command to be executed. not printed on console
I tried that. it does not work. I get No such file or directory.
I also tried replacing idouble quotes with uptick `, so it can be executed. but it does not
@brainstorm Don't put double quote or backticks or anything else in the function. It should be function startdocker(){ docker run -d ... $1; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.