Manny
Manny

Reputation: 79

Why i'm getting 403 error while creating a docker image?

Dockerfile:

FROM python:3.19-alpine

WORKDIR /app

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PATH="/PY/BIN:$PATH"

RUN pip install --upgrade pip

COPY ./req.txt /app/req.txt
COPY . /app

RUN pip install -r req.txt

docker-compose.yml:

version: '3.8'

services:
  django:
    container_name: django_celery_project
    build:
      context: ./
      dockerfile: Dockerfile
    command: sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
    volumes:
      - .:/app
    ports:
      - "8000:8000"
    environment:
      - ALLOWED_HOSTS=localhost,127.0.0.1
      - DEBUG=True
      - SECRET_KEY=***********

command : docker-compose up -d --build

result :

=> [django internal] load .dockerignore 0.0s => => transferring context: 87B 0.0s => [django internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 270B 0.0s => ERROR [django internal] load metadata for docker.io/library/python:3.19-alpine 10.7s => [django auth] library/python:pull token for registry-1.docker.io 0.0s

error : failed to solve: python:3.19-alpine: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 403 Forbidden

My IP address without a VPN is: 93.115.225.147

My IP address with VPN is: 213.142.149.230

Upvotes: 1

Views: 3641

Answers (2)

BercX
BercX

Reputation: 11

The problem could be that your country is blocked in the docker hub. To check this, just open https://registry-1.docker.io/ in your browser and check that you are not getting "403 Forbidden".

If you are blocked, you can use VPN, proxy or docker hub mirrors. The easiest option to fix the problem is to write google mirrors in /etc/docker/daemon.json and restart docker:

{
  "registry-mirrors": [
    "https://mirror.gcr.io"
  ]
}

Upvotes: 1

Manny
Manny

Reputation: 79

I solved this problem by pulling the python:alpine3.19 from the command line with this command :

docker pull python:alpine3.19

and then I ran the " docker-compose up -d --build " once again and the image was built properly.

Iranians should use a VPN throughout the process.

Upvotes: 3

Related Questions