docker-compose 无法构建

huangapple go评论69阅读模式
英文:

docker-compose unable to build

问题

这是我使用docker-compose build正在构建的Docker文件,它一直停在9/38处,构建过程无法完成。以下是Docker文件的主要代码部分:

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

# 拉取官方基础镜像
FROM --platform=linux/amd64 python:3.9-slim as builder

# 设置工作目录
WORKDIR /app

# 设置环境变量
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# 安装系统依赖
RUN apt-get update -y && \
    apt-get install -y --no-install-recommends gcc python3-psycopg2 apache2 apache2-dev default-libmysqlclient-dev

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

# 拉取官方基础镜像
FROM --platform=linux/amd64 python:3.9-slim

# 安装psycopg2依赖
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"]

我正在构建这个Docker文件,但它卡住了,错误似乎是:

[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

错误信息:

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/*"
英文:

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/*"

答案1

得分: 0

从您提供的yml配置文件来看,它似乎是不完整的。缺少COPYADD命令将应用程序代码复制到Docker镜像中。如果没有这个命令,应用程序代码将不会包含在镜像中,后续的命令可能会失败。

命令RUN ["chmod", "+x", "./start.sh"]CMD ["sh", "-c", "./start.sh"]在没有将shell文件复制到镜像中的情况下不会运行。

超时可能是网络问题,请检查您的互联网连接。

以下是包含COPY . /app指令的更新的Dockerfile:

###########
## BUILDER ##
###########

# 拉取官方基础镜像
FROM --platform=linux/amd64 python:3.9-slim as builder

# 设置工作目录
WORKDIR /app

COPY . /app

# 设置环境变量
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# 安装系统依赖
RUN apt-get update -y && \
    apt-get install -y --no-install-recommends gcc python3-psycopg2 apache2 apache2-dev default-libmysqlclient-dev

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

# 拉取官方基础镜像
FROM --platform=linux/amd64 python:3.9-slim

# 安装psycopg2依赖
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"]
英文:

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"]

huangapple
  • 本文由 发表于 2023年7月6日 11:53:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76625391.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定