0

I'm copying aliases.sh into an alpine-based container:

FROM php:8.1-fpm-alpine AS php

COPY .docker/aliases.sh /etc/profile.d/

CMD ["php-fpm"]

When I log into the shell, my aliases won't work. If I run:

source /etc/profile

The suddenly start working. Maybe I need to add source command into my Dockerfile but.. it doesn't make sense to me.

gremo
  • 339
  • 1
  • 4
  • 20

2 Answers2

0

Unix shells usually only load files like /etc/profile when they are started as a login shell. Ash, which is the default shell on Alpine, also does that.

From the ash manual:

A login shell first reads commands from the files /etc/profile and .profile if they exist.

Starting the shell with -l should start it as a login shell and it should read /etc/profile.

ash -l
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • Thanks, I was a bit unclear in my original question. I was using the "log into container" feature of Docker Desktop, so i was not "able" to specify `ash -l`. Solved using `ENV ENV="/etc/profile"` in `Dockerfile`. – gremo Aug 25 '22 at 08:51
0

ENV ENV="/etc/profile" is how I solved. Added it to the Dockerfile. Now despite how I log in into the container (using Docker Desktop, VS Code docker extension, etc.) I'm able to use the aliases provided by aliases.sh.

gremo
  • 339
  • 1
  • 4
  • 20
  • Could you please expand on this answer? I am not sure what you mean, but want to have a couple of aliases set up in a dev container environment for VScode. – Paidoo Apr 12 '23 at 19:07