dockerdocker-composedjango-celerycelerybeat

docker-compose unable to build


This is the Docker file I am building using docker-compose build, and its always stuck on 9/38 and its building process is not finishing. Here is the main code of the docker file:

`###########
## BUILDER ##
###########

# pull official base image
FROM --platform=linux/amd64 python:3.9-slim as builder

# set work directory
WORKDIR /app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install system dependencies
RUN apt-get update -y && \ 
    apt-get install -y --no-install-recommends gcc python3-psycopg2 apache2 apache2-dev default-libmysqlclient-dev

#########
# FINAL #
#########

# pull official base image
FROM --platform=linux/amd64 python:3.9-slim

# install psycopg2 dependencies
RUN apt update -y && apt-get install -y default-mysql-client wget python3-psycopg2 apache2 build-essential libpq-dev wkhtmltopdf && rm -rf /var/lib/apt/lists/*

EXPOSE 8080
RUN ["chmod", "+x", "./start.sh"]
CMD ["sh", "-c", "./start.sh"]

I am building this dockerfile, but its getting stuck, the error seems to be :

[celery-worker stage-1  2/14] RUN apt update -y && apt-get install -y default-mysql-client wget python3-psycopg2 apache2 build-essential libpq-dev wkht  248.8s 
 => [celery-worker builder 3/8] RUN apt-get update -y &&     apt-get install -y --no-install-recommends gcc python3-psycopg2 apache2 apache2-dev default-li  248.8s

Error message:

CANCELED [celery-worker builder 3/8] RUN apt-get update -y &&     apt-get install -y --no-install-recommends gcc python3-psycopg2 apache2 apache2-dev d  433.7s 
 => ERROR [celery-beat stage-1  2/14] RUN apt update -y && apt-get install -y default-mysql-client wget python3-psycopg2 apache2 build-essential libpq-dev   433.7s 
------
 > [celery-beat stage-1  2/14] RUN apt update -y && apt-get install -y default-mysql-client wget python3-psycopg2 apache2 build-essential libpq-dev wkhtmltopdf && rm -rf /var/lib/apt/lists/*:
0.771
0.771 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
0.771
3.958 Get:1 http://deb.debian.org/debian bookworm InRelease [147 kB]
8.457 Get:2 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
13.23 Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
22.09 Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8904 kB]
173.5 Ign:4 http://deb.debian.org/debian bookworm/main amd64 Packages
191.7 Ign:5 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages
198.9 Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8904 kB]
228.9 Ign:4 http://deb.debian.org/debian bookworm/main amd64 Packages
239.2 Get:5 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [47.3 kB]
262.9 Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8904 kB]
429.6 Ign:4 http://deb.debian.org/debian bookworm/main amd64 Packages
433.6 Ign:4 http://deb.debian.org/debian bookworm/main amd64 Packages
433.6 Err:4 http://deb.debian.org/debian bookworm/main amd64 Packages
433.6   Connection timed out [IP: 199.232.22.132 80]
433.6 Ign:4 http://deb.debian.org/debian bookworm/main amd64 Packages
433.6 Err:4 http://deb.debian.org/debian bookworm/main amd64 Packages
433.6   Connection timed out [IP: 199.232.22.132 80]
433.6 Ign:4 http://deb.debian.org/debian bookworm/main amd64 Packages
433.6 Err:4 http://deb.debian.org/debian bookworm/main amd64 Packages
433.6   Connection timed out [IP: 199.232.22.132 80]
433.7 Fetched 294 kB in 7min 13s (680 B/s)
433.7 Reading package lists...
433.7 E: Failed to fetch http://deb.debian.org/debian/dists/bookworm/main/binary-amd64/Packages  Connection timed out [IP: 199.232.22.132 80]
433.7 E: Some index files failed to download. They have been ignored, or old ones used instead.
------
failed to solve: process "/bin/sh -c apt update -y && apt-get install -y default-mysql-client wget python3-psycopg2 apache2 build-essential libpq-dev wkhtmltopdf && rm -rf /var/lib/apt/lists/*"

Solution

  • From the yml configuration file you provided, it seems to be incomplete.Missing the COPY or ADD command to copy the application code into the Docker image. Without this command, the application code won't be included in the image, and the subsequent commands may fail.

    The commands RUN ["chmod", "+x", "./start.sh"] CMD ["sh", "-c", "./start.sh"] will not run without copying the shell file into the image.

    The timeout is probably a network issue, check your internet connection

    Here is the updated Dockerfile that icludes the COPY . /app directive:

    ###########
    ## BUILDER ##
    ###########
    
    # pull official base image
    FROM --platform=linux/amd64 python:3.9-slim as builder
    
    # set work directory
    WORKDIR /app
    
    COPY  . /app
    
    # set environment variables
    ENV PYTHONDONTWRITEBYTECODE 1
    ENV PYTHONUNBUFFERED 1
    
    # install system dependencies
    RUN apt-get update -y && \ 
        apt-get install -y --no-install-recommends gcc python3-psycopg2 apache2 apache2-dev default-libmysqlclient-dev
    
    #########
    # FINAL #
    #########
    
    # pull official base image
    FROM --platform=linux/amd64 python:3.9-slim
    
    # install psycopg2 dependencies
    RUN apt update -y && apt-get install -y default-mysql-client wget python3-psycopg2 apache2 build-essential libpq-dev wkhtmltopdf && rm -rf /var/lib/apt/lists/*
    
    EXPOSE 8080
    RUN ["chmod", "+x", "./start.sh"]
    CMD ["sh", "-c", "./start.sh"]