4

I have a dockerfile like this:

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

Everything works fine except for the last command which runs a python package (django-bakery) through manage.py build. I don't get any errors.

This command should output some files inside build_static directory in the container.

If I ssh into the container and run the command manually then it is working. I inserted the full path with /code/ to make sure that they match and created all necessary directories beforehand.

This is how I build the container:

docker-compose run django /bin/bash

This is my docker-compose:

version: '3'

services:
  django:
    build: .
    volumes:
      - .:/code
    ports:
      - "8000:8000"

I wonder how come it is working when I run the command manually through bash inside the container, but not working with the command in the dockerfile.

Thanks!

Update (it seems that the files are created, but then if I check on them they aren't there):

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
2
  • What command you are using to ssh into the container ? Commented Apr 30, 2018 at 10:08
  • @fly2matrix it does it automatically after creating the container. otherwise I use docker exec -it id bash Commented Apr 30, 2018 at 10:38

2 Answers 2

1

Try following steps and let me know output:

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  
RUN ls -l /code/reports/build_static/  # should give you expected list of files

Give me output for the last step. I'll help you out based on output.

Sign up to request clarification or add additional context in comments.

4 Comments

yes, that one gives me the right output. but then there is nothing in there if I run the command manually after I ssh in the container. I updated the question with the result
Is it something related to the volumes? the fact that I have a build_static folder already which is empty? If so, what can one do?
I removed volumes: - .:/code from docker-compose.yml and now it stays there. So I think that was it. Thank you so much, you directed me to the right solution.
Actually YES : It is an issue with volume... Try removing that part from docker-compose.yml and you will see all your files.
1

The following Dockerfile, copies your current directory content to a code folder (if it doesn't exist, it creates it), then sets it as the workdir.

The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile

Then, in order to reduce you docker image size to the maximum, we regroup all your commands in one RUN command so that it reduces the number of layers.

FROM python:3

ENV PYTHONUNBUFFERED 1

COPY . /code
WORKDIR /code

RUN pip install -r requirements.txt && \
    ls -l reports/report/manage.py && \
    ls -l reports/build_static/ && \
    python reports/report/manage.py build full_report.views.RenderView

I haven't tried it with a full Django app example, but it should help you narrow down the problem !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.