Home > Blockchain >  Docker container cant install any package by apt with apt update before
Docker container cant install any package by apt with apt update before

Time:10-11

I have a problem in my docker container that I can't install any package via apt install in the docker file. I've seen on the internet 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.

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.

Below is the output of my 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"]

CodePudding user response:

do apt-get update first so apt knows what packages are in the repos

CodePudding user response:

Official php docker image clean up the apt cache at the end of the build process to reduce image size.

rm -rf /var/lib/apt/lists/* at line 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.

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