For Docker Containers we use Alpine Linux, like Node:Alpine, to make our images as small as possible. But somethimes you want to login on that Container. It would be convenient to have your aliases in that Container.
When we use standard Linux, we map a .bashrc to /root/.bashrc and have all our aliasses available.
But I cannot find the .bashrc equivalent for Alpine Linix.
I've tried:
- .bashrc
- .bash_profile
- .profile
- .ash_profile
- .ashrc
All not working.
Additional information
Alpine Linux is started in a Docker Container.
Dockerfile
FROM node:alpine
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/build .
Login to the container
I use the following command from the Host (my OSX macbook)
docker exec -it <containerName> /bin/sh
docker-compose.yml
jobrunner:
build:
context: ./build
dockerfile: Dockerfile
image: jobrunner:1.0
volumes:
- ./deployment/jobs/root/.bashrc:/root/.bashrc
- ./deployment/jobs/root/.bashrc:/root/.profile
- ./logs:/usr/src/app/logs
- ./data:/usr/src/app/data
environment:
NODE_ENV: production
restart: unless-stopped
container_name: JobHelloWorld
command: ["node", "./src/job_starter.js"]
Starting the container with:
docker-compose up -d
In the Container
When I enter the container with
docker exec -it <containername> /bin/sh
and then the output of the commands requested in the comments:
/usr/src/app # echo $SHELL
/usr/src/app # ps -p $$
ps: unrecognized option: p
BusyBox v1.32.1 () multi-call binary.
Usage: ps [-o COL1,COL2=HEADER] [-T]
Show list of processes
-o COL1,COL2=HEADER Select columns for display
-T Show threads
/usr/src/app #
ps -ef
I guess the output of 'ps -ef' is also intersting:
/usr/src/app # ps -ef
PID USER TIME COMMAND
1 root 0:00 sleep 360d
8 root 0:00 sh
16 root 0:00 ps -ef
it shows the sh shell (correct?). But the startup of /bin/sh does not work.
ps aux | grep $$
/usr/src/app # ps aux | grep $$
19 root 0:00 /bin/sh
26 root 0:00 grep 19
/bin/sh is a link
/usr/src/app # ls -la /bin/sh
lrwxrwxrwx 1 root root 12 Apr 14 10:25 /bin/sh -> /bin/busybox
Small test changing .profile
/usr/src/app # cat ~/.profile
alias l='ls $LS_OPTIONS -la'
export foo="bar"
/usr/src/app #
/usr/src/app # echo $foo
/usr/src/app #
/usr/src/app # . ~/.profile
Job-/usr/src/app# echo $foo
bar
Job-/usr/src/app#
As you see, the .profile does work, it just is not executed upon log in onto Alpine Linux in a Docker environment, or Alpine does not execute .profile upon login.
echo $SHELLand you can see what you're currently running withps -p $$. Please [edit] your question and add the output of both commands. – terdon Aug 17 '21 at 08:15/bin/shshould be a symlink most likely. Where does it point to? – Panki Aug 17 '21 at 08:46ps -p, it looks like you are using busyboxpsbut yes, it does indeed look like you are using a simplesh. Most likely busyboxshas well. Just to be sure, you can check withps aux | grep $$. You say that~/.profiledidn't work? That suggests you aren't running a login shell. Which is odd. When/how do you log into the container? If you addexport foo="bar"to/etc/profile, then log into the container and runecho $foo, do you getbar? – terdon Aug 17 '21 at 08:51docker exec -it <containername> /bin/shmanually? Can you change that todocker exec -it <containername> /bin/sh -l? That will launch a login shell which should let you use~/.profile. – terdon Aug 17 '21 at 08:54