我正在与Django合作,目前尝试移动我的本地开发人员。到Docker。我设法运行我的Web服务器。但是,我还没有npm install
。那就是我被困住的地方,我找不到文档或好的例子。以前有做过的人吗?
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/*
# Copy the current directory contents into the container at /app
COPY . /app
# Set the working directory to /app
WORKDIR /app
# Install Python dependencies
RUN pip install pipenv
RUN pipenv install --system --deploy --dev
COPY ./docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
docker-compose:
version: '3'
services:
db:
image: postgres
ports:
- "5432:5432"
environment:
# Password will be required if connecting from a different host
- POSTGRES_PASSWORD=django
web:
build: .
env_file: .env
volumes:
- .:/app
ports:
- "8000:8000"
depends_on:
- db
container_name: django
docker-entrypoint.sh
#!/bin/bash
# Apply database migrations
echo "Apply database migrations"
python manage.py migrate
# Run tests (In progress)
# echo "Running tests"
# pytest
# Start server
echo "Starting server"
python manage.py runserver 0.0.0.0:8000
答案 0 :(得分:1)
很简单,您应该遵循以下说明:
npm install
//or
yarn install
这将安装所有node_modules,当在当前目录中找不到它时,它将在目录上方搜索 node_modules 。
希望这能回答您的问题。
答案 1 :(得分:0)
在Dockerfile中只需添加: 运行npm install
这将查看当前目录中是否存在package.json,如果存在,它将安装所有依赖项。