我有一个Docker容器,其中有两个conda环境。绝大多数时间都使用一个,所以我想在那种环境下自动启动(目前是在基本环境下启动)。基于this website,我尝试将其添加到Dockerfile的末尾:
# Activate env
SHELL ["conda", "run", "-n", "py3", "/bin/bash", "-c"]
ENTRYPOINT ["conda", "run", "-n", "py3", "python", "pass.py"]
其中run.py仅包含print("hello world")
。
这导致脚本运行,但是我运行docker容器后docker容器没有保持打开状态,尽管删除这些行时也是如此。如何在指定的环境中打开容器并保持打开状态?
我的Dockerfile如下所示:
FROM nvidia/cuda:10.1-cudnn7-devel-centos7
WORKDIR /app/
COPY ./*.* ./
ENV CONDA_DIR "/opt/conda"
ENV PATH "$CONDA_DIR"/bin:$PATH
ONBUILD ENV PATH "$CONDA_DIR"/bin:$PATH
RUN \
yum -y install epel-release && \
yum -y update && \
yum install -y \
bzip2 \
curl \
which \
libXext \
libSM \
libXrender \
git \
cuda-nvcc-10-1 \
openssh-server \
postgresql-devel \
yum clean all && rm -rf /var/cache/yum/*
RUN CONDA_VERSION="4.7.12" && \
curl -L \
https://repo.continuum.io/miniconda/Miniconda3-${CONDA_VERSION}-Linux-x86_64.sh -o miniconda.sh && \
mkdir -p "$CONDA_DIR" && \
bash miniconda.sh -f -b -p "$CONDA_DIR" && \
echo "export PATH=$CONDA_DIR/bin:\$PATH" > /etc/profile.d/conda.sh && \
rm miniconda.sh && \
conda config --add channels conda-forge && \
conda config --set auto_update_conda False && \
pip install --upgrade pip && \
rm -rf /root/.cache/pip/*
RUN conda env create -f py2_env.yaml
RUN conda env create -f py3_env.yaml
# Activate env
SHELL ["conda", "run", "-n", "py3", "/bin/bash", "-c"]
ENTRYPOINT ["conda", "run", "-n", "py3", "python", "pass.py"]