manage.py no such file or dir - docker

I've got this Dockerfile:
FROM python:3.6.9-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt
COPY . /usr/src/app
CMD ["python", "manage.py", "run -h 0.0.0.0"] # <--
On the last line I'm getting python: can't open file 'manage.py': [Errno 2] No such file or directory
docker-compose.yml:
version: '3.7'
services:
users:
build:
context: ./users
dockerfile: Dockerfile
volumes:
- './services/users:/usr/src/app'
ports:
- 5001:5000
environment:
- FLASK_APP=project/__init__.py
- FLASK_ENV=development
I've got manage.py in the same directory as the Dockerfile (located in users dir). Where does it look for it ?

Issue solved by editing volumes:
- './services/users:/usr/src/app'
to:
volumes:
- './users:/usr/src/app'

Related

Nestjs wont reload in file change

Dockerfile:
\`FROM node:lts-alpine as development
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn --frozen-lockfile --production=false
COPY . .
RUN yarn prisma generate
RUN yarn build
FROM node:lts-alpine as production`your text`
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn --frozen-lockfile --production=true
COPY --from=development /usr/src/app/dist ./dist
COPY --from=development /usr/src/app/prisma ./prisma
EXPOSE 3000
CMD \["yarn", "start:prod"\]\`
docker-compose.yml:
version: '3.7'
services:
postgres_db:
image: postgres:12.2
container_name: postgres_db
restart: always
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: user
POSTGRES_DB: db
ports:
- 5432:5432
volumes:
- ./db:/var/lib/postgresql/data
nestjs_server:
build:
context: ./nestjs_server
dockerfile: Dockerfile
target: development
container_name: nestjs_server
volumes:
- ./nestjs_server:/usr/src/app
- /usr/src/app/node_modules
restart: always
environment:
DATABASE_URL: "postgresql://user:password#postgres_db:5432/mydb?schema=public"
ports:
- 3000:3000
depends_on:
- postgres_db
command: yarn start:debug
volumes:
postgres_db:
name: postgres_db
Structure:
It works perfectly fine but when I change something on the files I won't recompile.

What mean th error: Invalid compose project?

I'm learning how to run django rest with docker. I created an image, and I it's work when I use the command: docker run -p 8000:8000 docker_django_tutorial
But now I want to run this image through a docker-compose.yml file. Here is mine (it's based on a youtube vidéo, that why I don't understand why it doesn't work f
or me):
version: '3'
services:
monapp:
image: docker_django_tutorial
ports:
- 8000:8000
networks:
- monreaseau
networks:
monreseau:
When I run docker-compose up I've got the following error:
service "monapp" refers to undefined network monreaseau: invalid compose project
Just in case, here is my Dockerfile use for my image docker_django_tutorial:
#Use the Python3.7.2 container image
FROM python:3.7.2-stretch
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED 1
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
#RUN python3 manage.py runserver
Thank you for you're anwsers.
Someone help me re-write my files like this:
Docker file:
#Use the Python3.7.2 container image
FROM python:latest
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED 1
#CMD ["python3", "manage.py", "runserver", "0.0.0.0:90"]
#RUN python3 manage.py runserver
docker-compose.yml:
version: '3'
services:
monapp:
image: docker_django_tutorial
ports:
- 90:90
build: .
command: python3 manage.py runserver 0.0.0.0:90

Docker Compose with custom django app, ngnix, postgres, certbot, and letsencrypt

I am building my first customs Docker with Docker compose and I feel I am very close to finishing it but I have having an issue with what seem to be the entrypoint
FYI i am tryng to deploy a django app with postgres, nginx, certbot, letsencrypt
this is what I am seeing:
certbot_1 | /data/entrypoint.sh: exec: line 14: certbot: not found
nginx_1 | /data/entrypoint.sh: exec: line 14: run: not found
EDIT: I was able to make them run with the editted code but Ngnix exits with a code 0 and I don't know why and wont run
I have tried changing path with no luck
I am not sure what I am doing wrong
any advice you can provide would be great!
docker compose file:
version: '3.8'
services:
web:
build: .
command: gunicorn FleetOptimal.wsgi:application --bind 0.0.0.0:8000
environment:
- TZ=America/Toronto
volumes:
- /home/littlejiver/src/FleetOptimal/FleetOptimal/FleetOptimal/:/manage/
- /home/littlejiver/src/FleetOptimal/FleetOptimal/:/data/
- /home/littlejiver/src/FleetOptimal/FleetOptimal/FleetOptimal/staticfiles/:/static_volume/
- /home/littlejiver/src/FleetOptimal/FleetOptimal/FleetOptimal/images/:/media_volume/
expose:
- 8000
env_file:
- ./.env.dev
depends_on:
- db
db:
image: postgres:13.0-alpine
volumes:
- /home/littlejiver/docker/postgres/postgres_data:/postgres_data/
environment:
- PUID=1000
- PGID=1000
- TZ=Canada/Toronto
- POSTGRES_USER=someusername
- POSTGRES_PASSWORD=#somepassword
- POSTGRES_DB=somedb
nginx-proxy:
tty: true
image: nginx:latest
container_name: nginx-proxy
build: .
command: nginx -g "daemon off"
restart: always
environment:
- NGINX_DOCKER_GEN_CONTAINER=nginx-proxy-letsencrypt
ports:
- 443:443
- 80:80
volumes:
- /home/littlejiver/src/FleetOptimal/FleetOptimal/:/data/
- /home/littlejiver/src/FleetOptimal/FleetOptimal/FleetOptimal/staticfiles/:/static_volume/
- /home/littlejiver/src/FleetOptimal/FleetOptimal/FleetOptimal/images/:/media_volume/
- certs:/etc/nginx/certs
- html:/usr/share/nginx/html
- vhost:/etc/nginx/vhost.d
- /var/run/docker.sock:/tmp/docker.sock:ro
depends_on:
- web
nginx-proxy-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
env_file:
- ./.env.dev
environment:
- NGINX_DOCKER_GEN_CONTAINER=nginx-proxy-letsencrypt
volumes:
- /home/littlejiver/src/FleetOptimal/FleetOptimal/:/data/
- /var/run/docker.sock:/var/run/docker.sock:ro
- certs:/etc/nginx/certs
- html:/usr/share/nginx/html
- vhost:/etc/nginx/vhost.d
- acme:/etc/acme.sh
depends_on:
- nginx-proxy
volumes:
postgres_data:
static_volume:
media_volume:
certs:
html:
vhost:
acme:
DockerFile for Ngnix:
FROM nginx:latest
COPY vhost.d/default /etc/nginx/vhost.d/default
COPY custom.conf /etc/nginx/conf.d/custom.conf
DockerFile for Web:
###########
# BUILDER #
###########
# pull official base image
FROM python:3.9.6-alpine as builder
# set work directory
WORKDIR /manage
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev
# lint
RUN apk add zlib-dev jpeg-dev gcc musl-dev
RUN pip install --upgrade pip
# RUN pip install flake8==3.9.2
COPY . .
# RUN flake8 --ignore=E501,F401 /manage
# install dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
#########
# FINAL #
#########
# pull official base image
FROM python:3.9.6-alpine
# create directory for the app user
# create the app user
RUN addgroup -S littlejiver && adduser -S littlejiver -G littlejiver
# create the appropriate directories
ENV HOME=/manage
ENV APP_HOME=/manage
WORKDIR $APP_HOME
# install dependencies
RUN apk add zlib-dev jpeg-dev gcc musl-dev
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /manage/requirements.txt .
RUN pip install --no-cache /wheels/*
# copy entrypoint.prod.sh
COPY ./entrypoint.sh .
RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.sh
RUN chmod +x $APP_HOME/entrypoint.sh
# copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R littlejiver:littlejiver $APP_HOME
# change to the app user
USER littlejiver
WORKDIR /manage
# run entrypoint.prod.sh
ENTRYPOINT ["sh", "/data/entrypoint.sh"]
entrypoint.sh
#!/bin/sh
if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."
while ! nc -z $SQL_HOST $SQL_PORT; do
sleep 0.1
done
echo "PostgreSQL started"
fi
exec "$#"
Thanks
-littlejiver
roughly based of this guide:

entrypoint.sh: exec: gunicorn: not found

When I build image from Dockerfile:
FROM python:3.8.3-alpine as builder
WORKDIR /usr/src/app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev jpeg-dev zlib-dev
RUN pip install --upgrade pip
COPY . .
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
FROM python:3.8.3-alpine
# create directory for the app user
RUN mkdir -p /home/app
# create the app user
RUN addgroup -S app && adduser -S app -G app
# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*
# copy entrypoint-prod.sh
COPY ./entrypoint.prod.sh $APP_HOME
# copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]
And next run containers. Show me:
web_1 | PostgreSQL started
web_1 | /home/app/web/entrypoint.prod.sh: exec: line 14: gunicorn: not found
entrypoint.prod.sh
#!/bin/sh
if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."
while ! nc -z $DB_HOST 5432; do
sleep 0.1
done
echo "PostgreSQL started"
fi
exec "$#"
I also have a problem with nginx because when I enter the address 0.0.0.0:1337 I get an error 502 bad gateway(failed (113: Host is unreachable)). I think it is related to the problem above.
docker-compose.yml
version: '3.7'
services:
nginx:
build: ./nginx
ports:
- "1337:80"
restart: always
networks:
- nginx_network
depends_on:
- web
web:
build:
context: .
dockerfile: Dockerfile
command: gunicorn znajdki.wsgi:application --bind 0.0.0.0:8000
expose:
- "8000"
env_file:
- ./.env.prod
networks:
- nginx_network
- postgres_network
depends_on:
- db
db:
image: postgres
volumes:
- postgres:/var/lib/postgresql/data
env_file:
- ./.env.prod.db
networks:
- postgres_network
networks:
nginx_network:
driver: bridge
postgres_network:
driver: bridge
volumes:
postgres:

Django app exits for multistage build image

I am trying to build a docker image in multiple stages. My app exits immediately after getting up
My Dockerfile:
################# Builder #####################
FROM python:3.6 AS dependencies
COPY ./requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install --user -r requirements.txt
################# Release #####################
FROM python:3.6-alpine AS release
WORKDIR /src/
COPY . /src
COPY --from=dependencies /root/.local /root/.local/
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
RUN mv /src/wait-for /bin/wait-for
RUN chmod +x /bin/wait-for
ENV PATH=/root/.local/bin:$PATH
ENTRYPOINT [ "/entrypoint.sh" ]
My docker-compose:
version: '3.4'
services:
django_app:
build: ./app
command: sh -c "wait-for db:5432 && python manage.py collectstatic --no-input && python manage.py runserver 0.0.0.0:8000"
ports:
- "8000:8000"
env_file:
- ./.env
volumes:
- ./app:/src/
restart: on-failure
db:
image: postgres:9.6
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=${POSTGRESQL_DB_USER}
- POSTGRES_PASSWORD=${POSTGRESQL_DB_PASSWORD}
- POSTGRES_DB=${POSTGRESQL_DB_NAME}
ports:
- 5432:5432
restart: on-failure
entrypoint.sh
#! /bin/sh
cd /src/ || exit
# Run migrations
echo "RUNNING MIGRATIONS" && python manage.py migrate
# echo "COLLECT STATIC" && python manage.py collectstatic --noinput
exec "$#"
If I use django image with single stage build, everything works fine. Not able to understand the problem here.

Resources