Docker Community Forums

Share and learn in the Docker community.

How to load shell aliases in an alpine container

I have written a DOCKER file, which uses as an image an private adapted alpine image, which contains a nginx server.

I love to have some shell aliases available, when working in the container and it drives me nuts, when they are missing. So I copy a small prepared file to /root/.profile, which works. I can view the file and it’s contents. But the file does not load only if I manually do . ~/.profile in the container then I have the aliases available.

What do I have to do, that my profile is automatically loaded after I started the container and connect into it’s shell?

FROM myprivatealpineimage/base-image-php:7.4.13


COPY ./docker/shared/bashrc /root/.profile

COPY ./docker/shared/ /tmp/scripts/
RUN chmod +x -R /tmp/scripts/ \
    && /tmp/scripts/ ${TIMEZONE}\
    && apk update\
    && apk add --no-cache git

RUN install-ext pecl/apcu pecl/imagick pecl/zip pecl/redis
RUN apk add --no-cache --repository gnu-libiconv
ENV LD_PRELOAD /usr/lib/ php

WORKDIR /var/www

Be advised a potential answer to your question is provided by this stack-overflow dialog

You can add aliases during the docker build like so:

Making our command line life a little easier…

RUN echo ‘alias ll=“ls -l”’ >> ~/.bashrc
RUN echo ‘alias la=“ls -la”’ >> ~/.bashrc