我的 docker 容器中有一個問題,我無法通過 apt install 在 docker 檔案中安裝任何軟體包。我在互聯網上看到過一些類似的問題,但之前都使用 apt update 解決了這些問題,但就我而言,我之前已經在 Dockerfile 中進行了 apt update 。
另一個非常奇怪的一點是腳本在我第一次構建它時已經運行,但是當我按下并再次呼叫構建時,它開始給出這個錯誤,我不知道它是什么。
我已經嘗試清除 docker 快取,洗掉影像以再次下載它們。
下面是我的 docker-compose build 的輸出
$ docker-compose build
webserver uses an image, skipping
db uses an image, skipping
Building app
Sending build context to Docker daemon 421.8MB
Step 1/9 : FROM php:7.3-fpm
---> fdccf4773f9e
Step 2/9 : WORKDIR /var/www/html/
---> Using cache
---> f373aeb9cd7f
Step 3/9 : RUN apt-get install -y libpq-dev
---> Running in 1a6e4ffb9d71
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package libpq-dev
The command '/bin/sh -c apt-get install -y libpq-dev' returned a non-zero code: 100
ERROR: Service 'app' failed to build : Build failed
Dockerfile:
FROM php:7.3-fpm
# Copy composer.lock and composer.json into the working directory
# Set working directory
WORKDIR /var/www/html/
# Install dependencies for the operating system softwa
RUN apt-get install -y libpq-dev
# Install extensions for php
RUN docker-php-ext-install pdo_pgsql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
RUN chown -R www-data:www-data \
/var/www/html/storage \
/var/www/html/bootstrap/cache
# Expose port 9000 and start php-fpm server (for FastCGI Process Manager)
EXPOSE 9000
CMD ["php-fpm"]
uj5u.com熱心網友回復:
官方 php docker image 在構建程序結束時清理 apt 快取以減小影像大小。
rm -rf /var/lib/apt/lists/*在第 209 行
所以你需要apt-get update在運行之前重建快取,apt-get install如果你想減小影像大小,你也可以在最后清理 apt 快取。
FROM php:7.3-fpm
# Copy composer.lock and composer.json into the working directory
# Set working directory
WORKDIR /var/www/html/
# Update apt cache
RUN apt-get update
#Install dependencies for the operating system softwa
RUN apt-get install -y libpq-dev
# Install extensions for php
RUN docker-php-ext-install pdo_pgsql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
RUN chown -R www-data:www-data \
/var/www/html/storage \
/var/www/html/bootstrap/cache
# Clean up apt cache
RUN rm -rf /var/lib/apt/lists/*
# Expose port 9000 and start php-fpm server (for FastCGI Process Manager)
EXPOSE 9000
CMD ["php-fpm"]
uj5u.com熱心網友回復:
首先做apt-get updateapt 知道 repos 中有哪些包
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/513526.html
