构建镜像docker命令

📅 发布时间:2026/7/8 21:24:51 👁️ 浏览次数:
构建镜像docker命令
1、有网的机器编写DockerFile文件FROM python:3.9-slim RUN apt-get update apt-get install -y \ libgl1 \ libglib2.0-0 \ rm -rf /var/lib/apt/lists/* # 设置工作目录 WORKDIR /app # 设置环境变量 ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # 复制依赖文件 COPY requirements.txt . # 安装依赖 RUN pip install --no-cache-dir -r requirements.txt # 复制项目代码 COPY . . # 暴露端口 EXPOSE 5000 # 启动命令 - 绑定到 0.0.0.0 CMD ["python", "-u", "app.py"]2、编写docker-compose文件services: webapp: build: . image: reservoir-app container_name: reservoir-webapp ports: - "5000:5000" nginx: image: nginx container_name: reservoir-nginx volumes: - ./nginx.conf:/etc/nginx/conf.d/default.conf depends_on: - webapp ports: - "18520:80"3、构建并启动docker-compose up -d