本地 Gulp 在 Docker 容器内未找到。

huangapple go评论66阅读模式
英文:

Local gulp not found inside docker container

问题

I am trying to rebuild a past project regarding Django and gulp.js. Gulp is used to build the static assets from Django. I am now dockerizing this project. In order to do it, I am using a python and node combo image from this hub. I install the necessary packages both from Django and node. I copy the source code into the container. Run gulp and ./manage.py runserver. When I run gulp, I get an error that the local gulp cannot be found in the directory.

app  | [06:49:46] Local gulp not found in /usr/src/app
app  | [06:49:46] Try running: yarn add gulp

I have this directory tree. The src/ holds the source codes and I copy this to the container. It holds the gulpfile.js and manage.py.

.
└── project/
    ├── dockerfiles/
    │   └── app.Dockerfile
    ├── src/
    │   ├── apps/
    │   ├── entrypoints/
    │   │   └── entrypoint-local.sh
    │   ├── gulpfile.js
    │   ├── manage.py
    │   ├── package.json
    │   └── package-lock.json
    ├── .local.env
    └── docker-compose.yml

Here is my docker-compose file.

version: "3.9"

  app:
    container_name: app
    build:
      dockerfile: ./dockerfiles/app.Dockerfile
    entrypoint: ./entrypoints/entrypoint-local.sh
    volumes:
      - ./src:/usr/src/app
      - static:/static
    ports:
      - "8000:8000"
    env_file:
      - .local.env

Here is how I build the app container.

# syntax=docker/dockerfile:1
FROM nikolaik/python-nodejs:python3.7-nodejs19-bullseye

WORKDIR /usr/src/app

RUN apt-get update \
    && apt-get install -y binutils libproj-dev libgeos-dev gdal-bin libgeoip1 libgdal-dev gdal-bin \
    && apt-get install -y build-essential libssl-dev libffi-dev python3-dev python3-pip python3-venv \
    && rm -fr /var/lib/apt/lists

RUN pip install --upgrade pip
COPY /src/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY /src/package*.json .
RUN npm install
RUN npm install -g gulp-cli
RUN npm install --save-dev gulp

COPY /src .

RUN chmod +x ./entrypoints --recursive

In my entrypoint, I first run gulp before ./manage.py runserver.

#!/bin/sh

python manage.py migrate --no-input
gulp
python manage.py runserver

The gulp command triggers the error from the above. I have tried placing a list directory in the entrypoint to check if gulpfile.js is present and can confirm it is present. I also tried to remove the gulp command and run ./manage.py runserver and the Django runs. Why am I getting that error and how to fix it?

英文:

I am trying to rebuild a past project regarding Django and gulp.js. Gulp is used to build the static assets from Django. I am now dockerizing this project. In order to do it, I am using a python and node combo image from this hub. I install the necessary packages both from Django and node. I copy the source code into the container. Run gulp and ./manage.py runserver. When I run gulp, I get an error that the local gulp cannot be found in the directory.

app  | [06:49:46] Local gulp not found in /usr/src/app
app  | [06:49:46] Try running: yarn add gulp

I have this directory tree. The src/ holds the source codes and I copy this to the container. It holds the gulpfile.js and manage.py.

.
└── project/
    ├── dockerfiles/
    │   └── app.Dockerfile
    ├── src/
    │   ├── apps/
    │   ├── entrypoints/
    │   │   └── entrypoint-local.sh
    │   ├── gulpfile.js
    │   ├── manage.py
    │   ├── package.json
    │   └── package-lock.json
    ├── .local.env
    └── docker-compose.yml

Here is my docker-compose file.

version: "3.9"

  app:
    container_name: app
    build:
      dockerfile: ./dockerfiles/app.Dockerfile
    entrypoint: ./entrypoints/entrypoint-local.sh
    volumes:
      - ./src:/usr/src/app
      - static:/static
    ports:
      - "8000:8000"
    env_file:
      - .local.env

Here is how I build the app container.

# syntax=docker/dockerfile:1
FROM nikolaik/python-nodejs:python3.7-nodejs19-bullseye

WORKDIR /usr/src/app

RUN apt-get update \
    && apt-get install -y binutils libproj-dev libgeos-dev gdal-bin libgeoip1 libgdal-dev gdal-bin \
    && apt-get install -y build-essential libssl-dev libffi-dev python3-dev python3-pip python3-venv \
    && rm -fr /var/lib/apt/lists

RUN pip install --upgrade pip
COPY /src/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY /src/package*.json .
RUN npm install
RUN npm install -g gulp-cli
RUN npm install --save-dev gulp

COPY /src .

RUN chmod +x ./entrypoints --recursive

In my entrypoint, I first run gulp before ./manage.py runserver.

#!/bin/sh

python manage.py migrate --no-input
gulp
python manage.py runserver

The gulp command triggers the error from the above. I have tried placing a list directory in the entrypoint to check if gulpfile.js is present and can confirm it is present. I also tried to remove the gulp command and run ./manage.py runserver and the Django runs. Why am I getting that error and how to fix it?

答案1

得分: 1

你正在容器内创建一个目录 /usr/src/appWORKDIR /usr/src/app),用于安装 Node.js 的要求。

然后,你使用卷映射覆盖了该目录:

    volumes:
      - ./src:/usr/src/app

这将会用 ./src 的内容来_替换_容器内的目录 /usr/src/app(刚刚安装所有要求的位置)。

英文:

You're creating a directory /usr/src/app inside the container (WORKDIR /usr/src/app) where you install the Node.js requirements.

Then you overwrite that directory with a volume mapping:

    volumes:
      - ./src:/usr/src/app

This will replace the directory /usr/src/app inside the container (where you just installed all the requirements) with the contents of ./src.

huangapple
  • 本文由 发表于 2023年4月17日 15:31:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定