[英]Docker container cant install any package by apt with apt update before
I have a problem in my docker container that I can't install any package via apt install in the docker file.我的 docker 容器出现问题,无法通过 apt install 在 docker 文件中安装任何 package。 I've seen on the inte.net some similar problems but they are all solved using apt update before, but in my case I already had apt update before in the Dockerfile.
我在 inte.net 上看到过一些类似的问题,但它们之前都使用 apt update 解决了,但就我而言,我之前已经在 Dockerfile 中进行了 apt update。
Another very curious point is that the script had worked the first time I built it, but when I pressed down and called the build again it started giving this error and I have no idea what it is.另一个非常奇怪的一点是,脚本在我第一次构建它时就起作用了,但是当我按下并再次调用构建时,它开始出现这个错误,我不知道它是什么。
I've already tried to clear the docker cache, remove the images to download them again.我已经尝试过清除docker缓存,删除图片重新下载。
Below is the output of my docker-compose build下面是我的 docker-compose build 的 output
$ 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: 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"]
do apt-get update
first so apt knows what packages are in the repos先执行
apt-get update
以便 apt 知道存储库中有哪些包
Official php docker image clean up the apt cache at the end of the build process to reduce image size.官方 php docker 图像在构建过程结束时清理 apt 缓存以减小图像大小。
rm -rf /var/lib/apt/lists/*
at line 209 rm -rf /var/lib/apt/lists/*
在第 209 行
So you need to rebuild the cache with apt-get update
before running apt-get install
and if you want reduce image size you can also clean up the apt cache at the end.所以你需要在运行
apt-get install
之前用apt-get update
重建缓存,如果你想减小图像大小,你也可以在最后清理 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"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.