Dockerfile - Resolving problem

Hello.

Enviroment infos.
Hostsystem: Win11
VirtualBox with Ubuntu server vm (latest LTSC version)

I am starting to learn Docker and i have a problem at the topc Dockerfile.
My Dockerfile contains the following:

FROM ubuntu:latest
RUN apt update && apt install -y nano

When i try to execute the command “docker build .” i got error messages. See below.
When i create and run a container manually and execute the two mentioned commands step by step then it works.
So, where is the problem ?
I tried some steps to solve that. No solution found till now.

Please share the output of docker info

Please share text, not screenshots. Easier to read on all devices, less data to be stored.

Maybe update to RUN apt update && apt search nano && apt install -y nano to see available packages.

root@docker1:~# docker info

Client: Docker Engine - Community
 Version:    29.1.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.30.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.40.3
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 2
 Server Version: 29.1.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1c4457e00facac03ce1d75f7b6777a7a851e5c41
 runc version: v1.3.4-0-gd6d73eb8
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.8.0-88-generic
 Operating System: Ubuntu 24.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 8.665GiB
 Name: docker1
 ID: 029c62a3-9035-4119-9693-28f135d07994
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false
 Firewall Backend: iptables

sooo, i tried the following.

RUN apt update && apt search nano → works
RUN apt update && apt search nano && apt install -y nano —> does not work. same behavior.

I can’t quote text from a screenshot, but it shows the problem with the domain name. I also noticed that in some environments, the domain generated for the sources don’t work, but I haven’t seen this issue recently. I think the sources files are not even the same depending on where I run the container. I never tried to figure out, and it should be possible. When I just create a container now without running it, I get the same sources which is not the same as you get.

That difference could also be explained if your latest is not the same as my latest. You could try docker pull before running the container from the image, just to make sure you are using the most recent latest.

If I run this command:

docker run --rm -it ubuntu:latest cat /etc/apt/sources.list.d/ubuntu.sources | grep -v '^#'

I get this:

Types: deb
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

## Ubuntu security updates. Aside from URIs and Suites,
## this should mirror your choices in the previous section.
Types: deb
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Which works, but not when I change the domain to what you have.

You could try saving my quoted content as ubuntu.sources and run the container this way:

docker run --rm -it -v ./ubuntu.sources:/etc/apt/sources.list.d/ubuntu.sources ubuntu:latest bash

apt search should list the available packages, check if nano is even available.

1 Like

Good advice. I mean apt search was used in the Dockerfile, but that will not return a non-zero exit code when there is no result for nano. So I assume there was no result, since the repository domains didn’t work even if the command itself did

Is it possible to report the problem directly to Docker?
Ticket?
Issue tracker?

Was reported.
WAiting for response.

Does anyone else have any ideas on how to solve this problem?

I had a pretty long post which you haven’t replied to. I assume you missed it after the next posts, but please, try what I suggested and make sure your latest ubuntu image is really the latest since the actual tag can change and you can have an old, outdated image. Try docker pull ubuntu:latest

Where? I couldn’t find it anywhere. Image-related issues could be reported in the repository of the image. In case of the official ubuntu image, I guess here:

https://github.com/docker-library/official-images/issues

Thanks for your help.
I was able to solve the problem myself with the following command.

docker system prune -af

To reset the system to factory settings.
Everything is running smoothly now.