在 docker 个容器中使用 AI 模型的最佳实践

Best practice working with AI models from inside docker containers

我是第一次使用 TensorFlow docker 图像。在我开始大量投资之前,我想确保我了解文件应该放在哪里。我应该存储、运行、创建、保存容器内的所有文件并稍后删除我想要的吗?主机上是否应该保留任何文件?

始终在容器外编辑文件。我建议您 Docker Compose 来设置您的 Docker 环境。这是一个例子:

# Use version 2.3 of Docker Compose to access the GPU with NVIDIA-Docker 
# (it's the only version that supports GPUs
version: '2.3'

services:

  ai_container:
    image: ai_container
    container_name: ai_container
    working_dir: /ai_container/scripts
    build:
      context: .
      dockerfile: Dockerfile
    # You may want to expose the port 6006 to use Tensorboard
    ports:
      - "6006:6006"
    # Mount your scripts,logs,results and datasets (with read-only)
    volumes:
      - ./scripts:/ai_container/scripts
      - ./logs:/ai_container/logs
      - ./results:/ai_container/results
      - /hdd/my_heavy_dataset_folder/:/datasets:ro
    # Depending on the task you may need extra memory
    shm_size: '8gb'
    # This enables the GPU (requires NVIDIA-Docker)
    runtime: nvidia
    # Start Tensorboard to keep the container alive
    command: tensorboard --host 0.0.0.0 --logdir /ai_container/logs