I am trying to troubleshoot a tutorial on udemy on Windows 10 but why my compose file is failing to run. I tried relogging into Docker and I am able to run Docker build python:3.9-slim-bullseye
successfully. Does anyone here see my issue and help me understand what is happening?
I think my issue with with the line:
apt-get update && apt-get install --no-install-recommends -y \
build-essential \
libpq-dev
The tutorial's original code is here on his github but most of my code is a straight copy from him. Here is a link to the repo I have of what was covered so far.
local.yml file
version: "3.9"
services:
api:
build:
context: .
dockerfile: docker/local/django/Dockerfile
command: /start
container_name: django-api
volumes:
- .:/app
- static_volume:/app/staticfiles
- media_volume:/app/mediafiles
ports:
- "8000:8000"
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
depends_on:
- postgres
- mailhog
networks:
- authors-api-live
postgres:
build:
context: .
dockerfile: ./docker/local/postgres/Dockerfile
container_name: postgres
# volumes: # This is also causing issues
# - local_postgres_data:/var/lib/postgresql/data
# - local_postgres_data_backups:/backups
env_file:
- ./.envs/.local/.postgres
networks:
- authors-api-live
mailhog:
image: mailhog/mailhog:v1.0.0
container_name: mailhog
ports:
- "8025:8025"
networks:
- authors-api-live
networks:
authors-api-live:
driver: bridge
volumes:
local_postgres_data_backups: {}
static_volume:
media_volume:
Django Dockerfile
ARG PYTHON_VERSION=3.9-slim-bullseye
FROM python:${PYTHON_VERSION} as python
# BUILD STAGE
FROM python as pthyon-build-stage
ARG BUILD_ENVIORMENT=local
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
libpq-dev
COPY ./requirements .
RUN pip wheel --wheel-dir /usr/src/app/wheels \
-r ${BUILD_ENVIORMENT}.txt
# RUN STAGE
FROM python as python-run-stage
ARG BUILD_ENVIORMENT=local
# ARG APP_HOME=/usr/src/app
ARG APP_HOME=/app
ENV PYTHONDONTWRITEBYTECODE 1
ENV UNBUFFERED 1
ENV BUILD_ENVIORMENT=${BUILD_ENVIORMENT}
WORKDIR ${APP_HOME}
RUN apt-get update && apt-get install --no-install-recommends -y \
libpq-dev \
gettext \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*
# use wheels to make installation faster
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
&& rm -rf /wheels/
# Copy in entrypoint to test connection to database
COPY ./docker/local/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint
# check if models are migrated
COPY ./docker/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start
# COPY ./docker/local/django/celery/worker/start /start-celeryworker
# RUN sed -i 's/\r$//g' /start-celeryworker
# RUN chmod +x /start-celeryworker
# COPY ./docker/local/django/celery/flower/start /start-flower
# RUN sed -i 's/\r$//g' /start-flower
# RUN chmod +x /start-flower
COPY . ${APP_HOME}
ENTRYPOINT ["/entrypoint"]
Error Message:
PS C:\Users\...\MasterDjangoRESTFrameworkWithDocker\authors-haven-api\authors-src> docker-compose -f local.yml up -d --remove-orphans
Building api
[+] Building 1.2s (9/18)
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/python:3.9-slim-bullseye 0.0s
=> [internal] load build context 0.2s
=> => transferring context: 5.14kB 0.1s
=> [python 1/1] FROM docker.io/library/python:3.9-slim-bullseye 0.0s
=> ERROR FROM docker.io/library/python-build-stage:latest 0.9s
=> => resolve docker.io/library/python-build-stage:latest 0.9s
=> CACHED [python-run-stage 1/11] WORKDIR /app 0.0s
=> CANCELED [python-run-stage 2/11] RUN apt-get update && apt-get install --no-install-recommends -y libpq-dev gettext && apt-get purge -y 1.0s
=> [auth] library/python-build-stage:pull token for registry-1.docker.io 0.0s
------
> FROM docker.io/library/python-build-stage:latest:
------
failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
ERROR: Service 'api' failed to build : Build failed
Looks like there's a typo on the line where you're assigning the build stage name.
FROM python as pthyon-build-stage
Change this to:
FROM python as python-build-stage
and the build stage should be named as expected for later stages.