Django collectstatic fails if volume is set

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Expected behavior: All static files to be copied into /code/staticfiles inside the container and mirrored on the host after specifying a volume in docker-compose.yml using: volumes: – ./staticfiles:/code/staticfiles Actual behavior: The proper directories are created on both the container and the host, but the static files are not collected in the image or copied to the volume on the host machine. Explanation: My image builds correctly if I build it using the Dockerfile and docker-compse.yml below. The command RUN python manage.py collectstatic –no-input properly collects the static files into the directory /code/staticfiles inside the container. Dockerfile: FROM python:3 COPY requirements.txt /code/ WORKDIR /code RUN pip install -r requirements.txt COPY . /code RUN python manage.py collectstatic –no-input docker-compose.yml: version: ‘3’ services: db: … web: build: . command: gunicorn config.wsgi:application –bind :8000 ports: – “8000:8000” depends_on: – db However, if I modify my docker-compose.yml as below, the /code/staticfiles directory is created but remains empty inside the container and ./staticfiles is created but remains empty on the host machine. version: ‘3’ services: db: … web: build: . volumes: – ./staticfiles:/code/staticfiles command: gunicorn config.wsgi:application –bind :8000 ports: – “8000:8000” depends_on: – db I expected the files to be collected and put into /code/staticfiles inside the container and for those files to be copied to /staticfiles on the host machine. Here is the output in the terminal when building the image: (venv) C:DevPythondjango-project>docker-compose build db uses an image, skipping Building web Step 1/6 : FROM python:3 —> 28a4c88cdbbf Step 2/6 : COPY requirements.txt /code/ —> Using cache —> 339ceb75db5c Step 3/6 : WORKDIR /code —> Using cache —> 38d48a3d5051 Step 4/6 : RUN pip install -r requirements.txt —> Using cache —> 289f338f6554 Step 5/6 : COPY . /code —> f932bf67841f Step 6/6 : RUN python manage.py collectstatic –no-input —> Running in 85e2bda154e8 152 static files copied to ‘/code/staticfiles’, 464 post-processed. Removing intermediate container 85e2bda154e8 —> b61de221c80b Successfully built b61de221c80b Successfully tagged django-template_web:latest (venv) C:DevPythondjango-project> I only have one day of experience with Docker and know the problem is due to my false assumptions of how volumes are handled, particularly regarding intermediate containers. What am I missing? submitted by /u/KimPeek [link] [comments]

X ITM Cloud News

Patricia

Leave a Reply

Next Post

Harbor Registry and Certs

Thu Sep 17 , 2020
Spread the love          I’m working with a Harbor registry that was set up by a third-party contractor just before my arrival. The SSL certificate from GoDaddy expired a while ago, and I got to find out about it when my coworker couldn’t pull images. Anyway, the root of my problem is […]
X- ITM

Cloud Computing – Consultancy – Development – Hosting – APIs – Legacy Systems

X-ITM Technology helps our customers across the entire enterprise technology stack with differentiated industry solutions. We modernize IT, optimize data architectures, and make everything secure, scalable and orchestrated across public, private and hybrid clouds.

This image has an empty alt attribute; its file name is x-itmdc.jpg

The enterprise technology stack includes ITO; Cloud and Security Services; Applications and Industry IP; Data, Analytics and Engineering Services; and Advisory.

Watch an animation of  X-ITM‘s Enterprise Technology Stack

We combine years of experience running mission-critical systems with the latest digital innovations to deliver better business outcomes and new levels of performance, competitiveness and experiences for our customers and their stakeholders.

X-ITM invests in three key drivers of growth: People, Customers and Operational Execution.

The company’s global scale, talent and innovation platforms serve 6,000 private and public-sector clients in 70 countries.

X-ITM’s extensive partner network helps drive collaboration and leverage technology independence. The company has established more than 200 industry-leading global Partner Network relationships, including 15 strategic partners: Amazon Web Services, AT&T, Dell Technologies, Google Cloud, HCL, HP, HPE, IBM, Micro Focus, Microsoft, Oracle, PwC, SAP, ServiceNow and VMware

.

X ITM