当前位置: 首页 > 工具软件 > docker-sshd > 使用案例 >

docker篇---docker-compose和dockerfile构建镜像

陆子默
2023-12-01

docker-compose和dockerfile构建镜像

docker-compose

该docker-compose 将主项目与 mongo和nvidia 这两个镜像联系在一起,作为依赖

version: '3.8'
services:
  my_project:
    build: project
    container_name: "object-detection"
    volumes:
      - /home/slifeai/project_object/num_1/project:/code
    ports:
      - "2223:22"
    depends_on:
      - mongo
    runtime: nvidia

  mongo:
    image: mongo:3.4
    container_name: "mongo_34"
    restart: always
    ports:
      - "27017:27017"
    volumes:
      - ./mongo/data:/data/db


  nvidia:
    image: nvidia/cuda:11.0-base
    command: nvidia-smi
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [ gpu, utility ]

Dockerfile

FROM python:3.7

ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility

WORKDIR /code
COPY . .
RUN apt-get update
RUN apt-get install vim ffmpeg libsm6 libxext6 cron openssh-server -y
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

# 修改容器時間
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai'>/etc/timezone

RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/'  /etc/ssh/sshd_config
RUN sed -i 's/UsePAM yes/UsePAM no/' /etc/ssh/sshd_config
RUN echo "root:123456" | chpasswd

RUN echo  "alias ll='ls -l'" >> ~/.bash_profile
RUN /bin/bash -c 'source  ~/.bash_profile;'

CMD ["python","app.py"]
 类似资料: