【问题标题】:Docker how to create custom docker with multiple images in pythonDocker如何在python中创建具有多个图像的自定义docker
【发布时间】:2020-06-06 07:32:48
【问题描述】:

我创建了一个使用多个包的 python 文件,例如 PyTorch、sklearn 等。 现在我想创建一个自定义 docker 文件,该文件为我在 python 文件中使用的每个包使用多个图像并在 docker 中运行它。直到现在我才明白。有人可以用

帮助我启动代码吗
1. import pytorch image
2.import/install sklearn package 
3. run a python file in the environment.

【问题讨论】:

标签: docker dockerfile docker-machine docker-registry


【解决方案1】:

我不确定我是否正确地回答了这个问题,但是下面的 docker 文件可以用来构建 docker python 图像。文件开始于 - 导入 python 官方 gem 之一 - 将项目文件复制到 docker 镜像 - 安装操作系统依赖项 - 安装 requirements.txt 文件中列出的 python 包。 - 定义容器命令。

# Use an official Python runtime as a parent image
FROM python:2.7-slim-stretch

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app


# Install client libs
RUN apt-get update && apt-get install -y --no-install-recommends \
        default-libmysqlclient-dev \
        gcc \
        vim \
        locales \
        dos2unix \
    && pip install pip==9.0.1 \
    && sed -i 's/^# en_US.UTF-8 UTF-8$/en_US.UTF-8 UTF-8/g' /etc/locale.gen \
    && locale-gen \
    && update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 \
    &&  pip install -r requirements.txt \
    &&  apt-get purge -y --auto-remove gcc \
    &&  apt-get clean \
    &&  rm -rf \
        /var/lib/apt/lists/* \
        /tmp/* \
        /var/tmp/* \
        /usr/share/man \
        /usr/share/doc \
        /usr/share/doc-base


CMD ["python", "my.py"]script

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-22
    • 2019-08-06
    • 2019-06-21
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2022-11-12
    相关资源
    最近更新 更多