skip to Main Content

When running docker-compose up --build I’m constantly getting this error.

 => [web internal] load build definition from Dockerfile                                                           0.0s
 => => transferring dockerfile: 1.58kB                                                                             0.0s
 => [web internal] load .dockerignore                                                                              0.0s
 => => transferring context: 279B                                                                                  0.0s
 => [web internal] load metadata for docker.io/library/python:3.8                                                  0.8s
 => CANCELED [web  1/14] FROM docker.io/library/python:3.8@sha256:7a82536f5a2895b70416ccaffc49e6469d11ed8d9bf6bcf  0.3s
 => => resolve docker.io/library/python:3.8@sha256:7a82536f5a2895b70416ccaffc49e6469d11ed8d9bf6bcfc52328faeae7c77  0.2s
 => => sha256:795c73a8d985b6d1b7e5730dd2eece7f316ee2607544b0f91841d4c4142d9448 7.56kB / 7.56kB                     0.0s
 => => sha256:7a82536f5a2895b70416ccaffc49e6469d11ed8d9bf6bcfc52328faeae7c7710 1.86kB / 1.86kB                     0.0s
 => => sha256:129534c722d189b3baf69f6e3289b799caf45f75da37035c854100852edcbd7d 2.01kB / 2.01kB                     0.0s
 => CANCELED [web internal] load build context                                                                     0.1s
 => => transferring context: 26.00kB                                                                               0.0s
failed to solve: Canceled: context canceled

This has been happening since yesterday, before my images would build and my application would run just fine.

  1. Tried identifying any processes/apps that interfere with the docker build process
  2. Reinstalled Docker Desktop completely
  3. Tried changing Python versions inside my Dockerfile

I’m quite lost as to what is going wrong, I’ve used python3.8 and python3.9 without issues before. Below is my dockerfile and docker-compose.

# Use an official Python runtime as the base image
FROM python:3.8

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV NODE_ENV production

# Create and set the working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends 
        default-mysql-client 
        software-properties-common 
        curl 
        gnupg 
    && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource.gpg 
    && echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x bullseye main" | tee /etc/apt/sources.list.d/nodesource.list 
    && apt-get update && apt-get install -y nodejs 
    && apt-get clean 
    && rm -rf /var/lib/apt/lists/*

# Verify that Node.js and npm are installed
RUN node --version
RUN npm --version

# Install Python dependencies
COPY requirements.txt .
RUN pip install --upgrade pip && 
    pip install -r requirements.txt

# Install Tailwind CSS and its peer dependencies
COPY package.json package-lock.json ./
RUN npm install

# Copy the current directory contents into the container
COPY . .

# Build the Tailwind CSS
RUN npm run build:css

RUN npm run watch:css

COPY entrypoint.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh

ENTRYPOINT ["./entrypoint.sh"]

# The main command to run when the container starts
CMD ["gunicorn", "--bind", ":8000", "bmlabs.wsgi:application"]

Docker-compose


services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 
      MYSQL_DATABASE:
      MYSQL_USER: 
      MYSQL_PASSWORD:
    networks:
      - backend

  web:
    build: .
    volumes:
      - .:/app
      - static_volume:/app/staticfiles
      - media_volume:/app/mediafiles
    depends_on:
      - db
    networks:
      - backend
    expose:
      - "8000"

  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/bmlabs.conf:/etc/nginx/conf.d/bmlabs.conf:ro
      - static_volume:/app/staticfiles
      - media_volume:/app/mediafiles
    depends_on:
      - web
    networks:
      - backend

networks:
  backend:

volumes:
  db_data:
  cache_data:
  static_volume:
  media_volume:

I am on Windows 10.

2

Answers


  1. Two solutions I found:

    1. Moving the docker-compose.yml and Dockerfile to another directory fixed this.

    2. Re-cloning project into a different sub directory (or any other dir as long as its different):

    • old: /project
    • new: /temp/project

    I’ve been having the same exact problem. I was just finishing a long day of developing and I probably ran the same docker-compose.yml file 1000 times, and then all of a sudden it stopped working with a similar error.

    failed to solve: Canceled: context canceled

    I tried:

    -restarting docker
    -restarting my computer
    -reinstalling docker
    -killed all containers
    -deleted all containers, images, volumes

    Login or Signup to reply.
  2. There was a similar problem.
    The options proposed by Maxwell worked, but only once. In order to rebuild the container again, I had to either move the Docker files or clone the project.

    In the end, it helped to downgrade to Docker Desktop version 4.22.0

    NB!: docker installed on Windows 11.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search