gpt4 book ai didi

python - 使用 Django、npm 和 gulp 创建 Docker 容器

转载 作者:行者123 更新时间:2023-11-28 18:57:38 28 4
gpt4 key购买 nike

我更改了本地开发人员。到 docker 。我使用 Django 框架。对于前端,我使用 gulp build 命令来“创建”我的文件。现在我尝试了很多,查看了 Cookiecutter 和 Saleor 项目,但在安装 npm 时仍然遇到问题,我可以在我的 Docker 容器中调用 gulp 构建命令。

我已经尝试添加:

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get update && apt-get install -y \
nodejs \

COPY ./package.json /app/
RUN npm install

虽然安装了 npm,但我仍然无法在我的容器中运行命令 gulp build。它只是说 gulp 是一个未知命令。所以看起来 npm 没有在我的 package.json 文件中安装定义的包。这里有人已经解决了这个问题并可以给我一些提示吗?

Dockerfile

# Pull base image
FROM python:3.7

# Define environment variable
ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get install -y \
# Language dependencies
gettext \
# In addition, when you clean up the apt cache by removing /var/lib/apt/lists
# it reduces the image size, since the apt cache is not stored in a layer.
&& rm -rf /var/lib/apt/lists/*

# Set the working directory to /app
WORKDIR /app

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

# Install Python dependencies
RUN pip install pipenv
RUN pipenv install --system --deploy --dev

docker-compose.py

version: '3'

services:
web:
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
env_file: .env
volumes:
- .:/app
ports:
- "8000:8000"
depends_on:
- db
entrypoint: ./compose/local/django/entrypoint.sh
container_name: myproject

db:
image: postgres
ports:
- "5432:5432"
environment:
# Password will be required if connecting from a different host
- POSTGRES_PASSWORD=password

更新 1:

# Pull base image
FROM combos/python_node:3_10

# Define environment variable
ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get install -y \
# Language dependencies
gettext \
# In addition, when you clean up the apt cache by removing /var/lib/apt/lists
# it reduces the image size, since the apt cache is not stored in a layer.
&& rm -rf /var/lib/apt/lists/*

# COPY webpack.config.js app.json package.json package-lock.json /app/
# WORKDIR /app
# RUN npm install

# Set the working directory to /app
WORKDIR /app

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

RUN npm install

# Install Python dependencies
RUN pip install pipenv
RUN pipenv install --system --deploy --dev

最佳答案

您确定在正确的目录中调用了 npm install 吗?您将 package.json 复制到 /app 但从未知文件夹运行 npm install。你可以试试:

COPY ./package.json /app/
RUN cd /app/ && npm install

但我认为无论如何你都想全局安装 gulp,所以你可以跳过 package.json 并只使用:

RUN npm install -g gulp-cli

这样无论调用 gulp 都应该在 PATH 中,而不仅仅是那个特定的目录。

另外,如果你想获得一个已经安装了 Python 3.7 和 Node.js 10 的 Docker 镜像,你可以使用 combos/python_node:3.7_10 .这是rebuilt daily包含两个图像的最新版本。

关于python - 使用 Django、npm 和 gulp 创建 Docker 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56483627/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com