【问题标题】:Is it possible to enable color support for a multiple inherited Docker container?是否可以为多个继承的 Docker 容器启用颜色支持?
【发布时间】:2020-05-27 08:27:54
【问题描述】:

我有一个容器,它继承自 nvidia cuda 10.2 ubuntu 18.04:

FROM nvidia/cuda:10.2-base-ubuntu18.04

# Install some basic utilities
RUN apt-get update && apt-get install -y \
    curl \
    wget \
    ca-certificates \
    sudo \
    git \
    bzip2 \
    libx11-6 \
 && rm -rf /var/lib/apt/lists/*

# Create a working directory and set it as default
RUN mkdir /app
RUN chmod 777 /app
WORKDIR /app

# Create a non-root user and switch to it
RUN adduser --disabled-password --gecos '' --shell /bin/bash user 
RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
USER user

# All users can use /home/user as their home directory
ENV HOME=/home/user
RUN chmod 777 /home/user

 # Install Miniconda
RUN wget -O ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh \
 && chmod +x ~/miniconda.sh \
 && ~/miniconda.sh -b -p ~/miniconda \
 && rm ~/miniconda.sh
ENV PATH=/home/user/miniconda/bin:$PATH
ENV CONDA_AUTO_UPDATE_CONDA=false

# Update Conda
RUN conda update conda

如果我使用环境变量 env TERM=xterm-256color 运行此容器,我将获得预期的彩色输出支持。

现在我有另一个 Docker 容器,它继承自我在上面粘贴的容器(标记:mlflowcore/base:1.0.0):

FROM mlflowcore/base:1.0.0

# Install the conda environment
COPY pytorch_environment.yml .
RUN conda env create -f pytorch_environment.yml && conda clean -a

# Activate the environment
RUN echo "source activate pytorch" > ~/.bashrc
ENV PATH /home/user/miniconda/envs/pytorch/bin:$PATH

# Dump the details of the installed packages to a file for posterity
RUN conda env export --name pytorch > pytorch.yml

# Currently required, since mlflow writes every file as root!
USER root

但是,当我使用变量 env TERM=xterm-256color 运行此容器或从 Docker 容器中设置 ENV TERM xterm-256color 变量时我没有获得颜色支持

如何为我的容器获得颜色支持,该容器继承自基于另一个容器的 Docker 容器?

非常感谢!

【问题讨论】:

    标签: docker terminal colors


    【解决方案1】:

    问题在于RUN echo "source activate pytorch" > ~/.bashrc 行覆盖了默认的 bashrc 文件。

    通过添加>:RUN echo "source activate pytorch" >> ~/.bashrc 将其更改为将命令附加到 bashrc 解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      • 2016-11-13
      • 2019-03-26
      • 2016-11-14
      • 2016-08-24
      • 1970-01-01
      相关资源
      最近更新 更多