我编写了一个 DOCKER 文件,它使用私有改编的 alpine 图像作为图像,其中包含 nginx 服务器。
注意:alpine 使用 zsh,而不是 bash。
当我在容器中工作时,我喜欢有一些可用的 shell 别名,当它们丢失时,它会让我抓狂。因此,我将一个准备好的小文件复制到 /root/.profile,这有效。我可以查看该文件及其内容。但仅当我手动加载时,该文件才不会加载。 ~/.profile 在容器中,然后我就有了可用的别名。
我需要做什么,才能在启动容器并连接到它的 shell 后自动加载我的配置文件?
FROM myprivatealpineimage/base-image-php:7.4.13
ARG TIMEZONE
COPY ./docker/shared/bashrc /root/.profile
COPY ./docker/shared/ /tmp/scripts/
RUN chmod +x -R /tmp/scripts/ \
&& /tmp/scripts/set_timezone.sh ${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 http://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
WORKDIR /var/www
默认情况下,docker 启动一个非登录 shell。
要读取 .profile 文件,您需要一个登录 shelldocker exec -it <container> ash -l
.
要每次读取 /etc/profile (或其他启动文件),您必须设置 ENV 变量。
Dockerfile 示例
ARG PHPVERSION=7.4
FROM php:$PHPVERSION-fpm-alpine
ARG PHPVERSION=7.4
ENV PHPVERSION_ENV=$PHPVERSION
# copy composer from official image
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
#set $ENV
ENV ENV=/etc/profile
#copy aliases definition
COPY /assets/alias.sh /etc/profile.d/alias.sh
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)