我有一个像这样的Dockerfile:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
ADD reports /code/
RUN pip install -r requirements.txt
ADD . /code/
RUN ls -l /code/reports/report/manage.py # gives expected result
RUN ls -l /code/reports/build_static/ # gives expected result
RUN python /code/reports/report/manage.py build full_report.views.RenderView # does not work
除了最后一个命令(通过
manage.py build
运行django-bakery Python包)之外,一切都很正常。我没有收到任何错误信息。该命令应在容器中的build_static目录下输出一些文件。
如果我手动连接到容器并运行该命令,则可以正常工作。我插入了完整路径
/code/
以确保它们匹配,并预先创建了所有必要的目录。这是我构建容器的方法:
docker-compose run django /bin/bash
这是我的docker-compose文件:
version: '3'
services:
django:
build: .
volumes:
- .:/code
ports:
- "8000:8000"
我想知道为什么在容器内通过bash手动运行命令时能够正常工作,但是使用Dockerfile中的命令却无法正常工作。
谢谢!
更新(看起来文件已经创建,但是如果我检查它们,它们就不在那里):
Step 12/12 : RUN ls -l /code/reports/build_static/
---> Running in e294563d26d5
total 11080
-rw-r--r-- 1 root root 11339956 Apr 30 10:53 index.html
drwxr-xr-x 7 root root 4096 Apr 30 10:53 static
Removing intermediate container e294563d26d5
---> b8e72da8ee5c
Successfully built b8e72da8ee5c
Successfully tagged image_django:latest
WARNING: Image for service django was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
root@7483853ecc45:/code# ls -l reports/build_static/
total 0
docker exec -it id bash
命令。 - Claudiu Creanga