我试图从现有的docker镜像中设置一个singularity容器,其中一个名为 "tensorflow "的conda环境在我运行该容器时就被激活。我在这个话题上找到了一些答案 here .不幸的是,在这篇文章中,他们只解释了如何设置singularity .def文件以默认激活conda环境。然而,我只想修改我现有的Docker文件,然后从中建立一个奇异的镜像。
到目前为止,我所尝试的是像这样设置Docker文件。
FROM opensuse/tumbleweed
ENV PATH /opt/conda/bin:$PATH
ENV PATH /opt/conda/envs/tensorflow/bin:$PATH
# Add conda environment files (.yml)
COPY ["./conda_environments/", "."]
# Install with zypper
RUN zypper install -y sudo wget bzip2 vim tree which util-linux
# Get installation file
RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2019.07-Linux-x86_64.sh -O ~/anaconda.sh
# Install anaconda at /opt/conda
RUN /bin/bash ~/anaconda.sh -b -p "/opt/conda"
# Remove installation file
RUN rm ~/anaconda.sh
# Make conda command available to all users
RUN ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh
# Create tensorflow environment
RUN conda env create -f tensorflow.yml
# Activate conda environment with interactive bash session
RUN echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc
RUN echo "conda activate tensorflow" >> ~/.bashrc
# Default command
CMD ["/bin/bash"]
构建docker镜像后,我运行docker容器。
docker run -t -d --rm --name=my_container opensuse_conda:latest
并进入容器与。
docker exec -it my_container bash
结果和预期的一样。shell会话直接启动,"tensorflow "环境处于活动状态,由(tensorflow)前缀表示。
为了从这个docker镜像中建立一个奇异的镜像,我使用。
sudo singularity build opensuse_conda.sif docker-daemon://opensuse_conda:latest
并运行该容器。
sudo singularity run opensuse_conda.sif
这就是问题发生的地方。默认情况下,"tensorflow "环境被激活,而不是 "base "环境。然而,我更希望当我运行奇异性容器时,"tensorflow "环境被激活。
我怎样才能修改我的Docker文件,以便在运行docker容器和singularity容器时,默认环境为 "tensorflow"?