我有一个基本的码头形象:
FROM ubuntu:21.04
WORKDIR /app
RUN apt-get update && apt-get install -y wget bzip2 \
&& wget -qO- https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj bin/micromamba \
&& touch /root/.bashrc \
&& ./bin/micromamba shell init -s bash -p /opt/conda \
&& cp /root/.bashrc /opt/conda/bashrc \
&& apt-get clean autoremove --yes \
&& rm -rf /var/lib/{apt,dpkg,cache,log}
SHELL ["bash", "-l" ,"-c"]并从中衍生出另一种:
ARG BASE
FROM $BASE
RUN source /opt/conda/bashrc && micromamba activate \
&& micromamba create --file environment.yaml -p /env在构建第二个映像时,我得到以下错误: RUN部分的micromamba: command not found。
Ubuntu有什么问题?为什么在第二码头形象建设中看不到micromamba?
PS使用脚手架进行建筑,这样才能正确理解,$BASE在哪里,它是什么。
发布于 2021-08-05 04:23:33
ubuntu:21.04映像附带了一个以以下开头的/root/.bashrc文件:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return当第二个Dockerfile执行RUN source /opt/conda/bashrc时,没有设置PS1,因此bashrc文件的其余部分不执行。bashrc文件的其余部分是进行micromamba初始化的地方,包括用于激活micromamba环境的micromamba bash函数的设置。
debian:buster映像有一个更小的/root/.bashrc,它没有类似于[ -z "$PS1" ] && return的行,因此会加载micromamba函数。
高寒图像不附带/root/.bashrc,因此它也不包含提前退出文件的代码。
如果您想使用ubuntu:21.04映像,可以首先修改您的Dockerfile,如下所示:
FROM ubuntu:21.04
WORKDIR /app
RUN apt-get update && apt-get install -y wget bzip2 \
&& wget -qO- https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj bin/micromamba \
&& touch /root/.bashrc \
&& ./bin/micromamba shell init -s bash -p /opt/conda \
&& grep -v '[ -z "\$PS1" ] && return' /root/.bashrc > /opt/conda/bashrc # this line has been modified \
&& apt-get clean autoremove --yes \
&& rm -rf /var/lib/{apt,dpkg,cache,log}
SHELL ["bash", "-l" ,"-c"]这将删除导致提前终止的一行。
或者,您可以使用现有的曼巴格/微曼巴坞映像。mambaorg/micromamba:latest是基于debian:瘦的,但是mambaorg/micromamba:jammy会给你一个基于ubuntu的映像(公开:我维护这个映像)。
https://stackoverflow.com/questions/68193812
复制相似问题