Cal*_*ane 5 docker alpine-linux
我编写了一个 DOCKER 文件,它使用私有改编的 alpine 镜像作为镜像,其中包含 nginx 服务器。\n注意:alpine 使用 zsh,而不是 bash。
\n当我在容器中工作时,我喜欢有一些可用的 shell 别名,当它们丢失时,它会让我抓狂。因此,我将一个准备好的小文件复制到 /root/.profile,这有效。我可以查看该文件及其\xe2\x80\x99s 内容。但仅当我手动加载时,该文件才不会加载。~/.profile 在容器中,然后我就有了可用的别名。
\n我需要做什么,才能在启动容器并连接到它\xe2\x80\x99s shell 后自动加载我的配置文件?
\nFROM myprivatealpineimage/base-image-php:7.4.13\n\nARG TIMEZONE\n\nCOPY ./docker/shared/bashrc /root/.profile\n\nCOPY ./docker/shared/ /tmp/scripts/\nRUN chmod +x -R /tmp/scripts/ \\\n && /tmp/scripts/set_timezone.sh ${TIMEZONE}\\\n && apk update\\\n && apk add --no-cache git\n\nRUN install-ext pecl/apcu pecl/imagick pecl/zip pecl/redis\nRUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv\nENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php\n\nWORKDIR /var/www\nRun Code Online (Sandbox Code Playgroud)\n
小智 4
默认情况下,docker 启动一个非登录 shell。要读取 .profile 文件,您需要一个登录 shell docker 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8796 次 |
| 最近记录: |