I am new to docker. I found that we can set environment variables using ENV instruction in the Dockerfile. But how does one set bash aliases for long commands in Dockerfile?
相关问题
- Docker task in Azure devops won't accept "$(pw
- JQ: Select when attribute value exists in a bash a
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- Why should we check WIFEXITED after wait in order
Basically like you always do, by adding it to the user's
.bashrc
:As usual this will only work for interactive shells:
For non-interactive shells you should create a small script and put it in your path, i.e.:
If your alias uses parameters (ie.
hi Jim
->hello Jim
), just add"$@"
:vi ~/.bash_aliases
source ~/.bash_aliases
To create an alias of an existing command, might also use
ln -s
:ln -s $(which <existing_command>) /usr/bin/<my_command>
If you want to use aliases just in Dockerfile, but not inside container then the shortest way is
ENV
declaration:And for use in container the way like already described:
Most of the time I use aliases just on building stage and do not go inside containers, so first example is quicker, clearer and simpler for every day use.
I just added this to my app.dockerfile
and inside the
initbash_profile.sh
which just appends my custom aliases and no need to source the .bashrc file.worked a treat!
Another option is to just use the "docker exec -it command" from outside the container and just use your own .bashrc or the .bash_profile (what ever you prefer)
eg.
docker exec -it docker_app_1 bash
I think the easiest way would be to mount a file into your container containing your aliases, and then specify where bash should find it:
Sample usage: