Unable to build a new container image

Hello,
I am trying to dockerize a full application using docker-compose, which has two tiers : db + web app.
Now, since the web app service, needs custom settings, like:

version: '3.6'

services:
 db:
  container_name: db
  image:  mariadb:10.3
  restart: always
  command: --default-authentication-plugin=mysql_native_password
  env_file:
   - .env
  ports:
   - "3306:3306"
  volumes:
   - ./db_init:/docker-entrypoint-initdb.d
   - ./db_data:/var/lib/mysql

 phpmyadmin:
  container_name: admin
  depends_on:
   - db
  image: phpmyadmin/phpmyadmin
  restart: always
  ports:
   - '8080:80'
  env_file:
   - .env

 web:
  container_name: webapp
  depends_on:
   - db
  build:
   context: ./app_dockerfile
   dockerfile: Dockerfile
  restart: always
  env_file:
   - .env
  volumes:
   - ./app:/var/www/html
  ports:
   - 809:80

I need to put all those settings in a Dockerfile which is as follows:

FROM php:7.4.12-apache
ENV http_proxy='http://10.60.120.254:8080/'
RUN echo "nameserver 10.55.20.5" > /etc/resolv.conf
RUN apt-get update && apt-get install -y libldap2-dev
CMD bash

But itā€™s always, blocked in the third service, with the following error:

Sending build context to Docker daemon  2.048kB
Step 1/5 : FROM php:7.4.12-apache
 ---> 84973bb59734
Step 2/5 : ENV http_proxy='http://10.60.120.254:8080/'
 ---> Using cache
 ---> f7ab9adfcc21
Step 3/5 : RUN echo "nameserver 10.55.20.5"
 ---> Using cache
 ---> 3334de78d241
Step 4/5 : RUN apt-get update && apt-get install -y libldap2-dev
 ---> Running in 26318a55853b
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Err:1 http://security.debian.org/debian-security buster/updates InRelease
  At least one invalid signature was encountered.
Get:2 http://deb.debian.org/debian buster InRelease [122 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Err:2 http://deb.debian.org/debian buster InRelease
  At least one invalid signature was encountered.
Err:3 http://deb.debian.org/debian buster-updates InRelease
  At least one invalid signature was encountered.
Reading package lists...
W: GPG error: http://security.debian.org/debian-security buster/updates InRelease: At least one invalid signature was encountered.
E: The repository 'http://security.debian.org/debian-security buster/updates InRelease' is not signed.
W: GPG error: http://deb.debian.org/debian buster InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian buster InRelease' is not signed.
W: GPG error: http://deb.debian.org/debian buster-updates InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian buster-updates InRelease' is not signed.
The command '/bin/sh -c apt-get update && apt-get install -y libldap2-dev' returned a non-zero code: 100

I donā€™t know, whatā€™s really blocking this operation, since i did add nameserver, proxy address for internet connectionā€¦
I would like to know, if you can help me here.
Thank you in advance,

I am not sure about the error but I am pretty sure you should not set the nameserver and the proxy inside the container during the build. Usually Docker is running under systemd which you can configure globally: Control Docker with systemd | Docker Documentation

Even if you need to use environment variables, I would use ARG instead of ENV in the dockerfile but that is just a small change.

The DNS can also be configured globally using --dns on dockerd: dockerd | Docker Documentation

If you change the content of resolv.conf you will loose that when you run a container from the image.

Now back to the question. Try to investigate this in a simple container instead of building a new image. If it works in a container, it will probably work during the build. Check if you can access any site thorugh the proxy from terminal. Try access the APT repository using curl to check if you see the right page.

There is one more thing that people are suggesting on other forums. They say it can be caused by an insufficient amount of disk space. ubuntu - Repository is not signed in docker build - Stack Overflow

If it can be the reason then I can imagine that you have enough space but for some reason it is not writable.

1 Like

Thank you @rimelek for your help!
I did manage to resolve the web app service build, while searching on internet, i found that it might be caused by some corrupt images, so i removed any stale images.
Then, tried to run docker build, and it was successful. Here is the final Dockerfile:

FROM php:7.4.12-apache
ENV http_proxy="http://10.60.120.254:8080"
RUN apt clean
RUN echo "nameserver 10.55.20.5" > /etc/resolv.conf
RUN apt-get update
RUN apt-get install -y libldap2-dev
RUN docker-php-ext-install mysqli
RUN docker-php-ext-install ldap
RUN apt-get install -y libc-client-dev libkrb5-dev && rm -r /var/lib/apt/lists/*
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && docker-php-ext-install imap
EXPOSE 80
CMD ["/usr/sbin/apache2ctl","-DFOREGROUND"]

and the docker-compose.yml file is as follows:

version: '3.6'

services:
 db:
  container_name: db
  image:  mariadb:10.3
  restart: always
  command: --default-authentication-plugin=mysql_native_password
  env_file:
   - .env
  ports:
   - "3306:3306"
  volumes:
   - ./db_init:/docker-entrypoint-initdb.d
   - ./db_data:/var/lib/mysql

 phpmyadmin:
  container_name: admin
  depends_on:
   - db
  image: phpmyadmin/phpmyadmin
  restart: always
  ports:
   - '8080:80'
  env_file:
   - .env

 web:
  container_name: webapp
  depends_on:
   - db
  build:
   context: ./app_dockerfile
   dockerfile: Dockerfile
  image: company_webserv
  restart: always
  env_file:
   - .env
  volumes:
   - ./app:/var/www/html
  ports:
   - 809:80

For the DNS, and proxy settings, i do have the docker machine,configured for DNS and proxy services, and it works correctly, but for containers, this did not help whatever i doā€¦
So, if you permit to give me some ideas about making it work properly, iā€™d be very grateful.
Thank you so much.

Docker machine? Are you on Windows?

no, i have ubuntu server 20.04 virtual machine, where i have docker installed

Have you checked the links I gave you? That is how I did it. If you need more advice on it, I recommend you to create a new topic and describe what you have already tried. I remember I had to set the proxy in multiple file but for the containers, I think systemd was enough. I would have to check my old solution to give you more details.

1 Like