To simplify test execution for several different container I want to create an alias to use the same command for every container.
For example for a backend container I want to be able to use docker exec -t backend test
instead of docker exec -t backend pytest test
So I add this line in my backend
Dockerfile :
RUN echo alias test="pytest /app/test" >> ~/.bashrc
But when I do docker exec -t backend test
it doesn't work, otherwise it works when I do docker exec -ti backend bash
then test
.
I saw that it is because alias in .bashrc
works only if we use interactive terminal.
How can I get around that?
CodePudding user response:
docker exec
does not run the shell, so .bashrc
is just never used.
Create an executable in PATH
, most probably in /usr/local/bin
. Note that test
is a very basic shell command, use a different unique name.
CodePudding user response:
That alias will only work for interactive shells, if you want that alias to work on other programs:
RUN echo -e '#!/bin/bash\npytest /app/test' > /usr/bin/mypytest && \
chmod x /usr/bin/mypytest