It been days since i’ve been trying to get my django app to work properly with docker.
I’m using django to handle backend, postgresql for database and vanilla js for frontend. So far so good, everything that has to do with database is good. I’m only using nodejs for tailwindcss but everytime i run docker-compose, i get the below error
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "npm": executable file not found in $PATH: unknown
I was previously using two Dockerfiles, one for python Dockerfile.python
and the other for node Dockerfile,nodejs
but `back4app isn’t allowing me to deploy for production with two Dockerfiles. So i resulted back to a single Dockerfile.
# Stage 1: Build the Node.js app
FROM node:18 AS nodejs_builder
WORKDIR /usr/src/nodejs_app
COPY package*.json ./
RUN npm install
RUN chown -R node /usr/src/nodejs_app/node_modules
COPY . .
# Use npm run dev for development
CMD npm run dev
# Stage 2: Build the Python app
FROM python:3.9 AS python_builder
WORKDIR /usr/src/python_app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
# Stage 3: Final image
FROM python:3.9
WORKDIR /usr/src/app
# Copy built Node.js app from Stage 1
COPY --from=nodejs_builder /usr/src/nodejs_app ./nodejs_app
# Copy built Python app from Stage 2
COPY --from=python_builder /usr/src/python_app ./python_app
# Expose the port your application will listen on
EXPOSE 8000
# Define the command to start your application
CMD python manage.py runserver 0.0.0.0:8000
Here is my docker-compose.dev.yml
file
version: '3'
services:
db:
image: postgres:latest
container_name: db
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- '5433:5432'
environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
PGDATA: /var/lib/postgresql/data/
nodejs:
build:
context: .
container_name: nodejs
tty: true
restart: on-failure
command: npm run dev
volumes:
- .:/usr/src/app
depends_on:
- db
django:
build:
context: .
container_name: django
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/usr/src/app
ports:
- '8000:8000'
depends_on:
- db
volumes:
pgdata:
I also have this project in this repository here: GitHub - TheJazzDev/typeguru
You can please check CONTRIBUTING.md
to run it locally if needs be. Thanks in advance.