Docker build fails: Cannot install packages

Hi,

I am trying to run my first C++ application on the imx8mm with a Verdin development board. Within VS Code I started a new Torizon Project and selected C++ Makefile Console Application. I can run the application successfully on my local machine. When I try to run it on the remote module it fails in the remote docker compose step with this log:

 *  Executing task in folder DockerTest: DOCKER_HOST= docker compose build --pull --build-arg SSHUSERNAME=torizon --build-arg APP_ROOT=/home/torizon/app --build-arg IMAGE_ARCH=arm64 --build-arg SSH_DEBUG_PORT=2230 --build-arg GPU=-vivante dockertest-debug 

WARN[0000] The "DOCKER_LOGIN" variable is not set. Defaulting to a blank string. 
[+] Building 243.3s (6/11)                                                                                                                                                                                         docker:default
 => [dockertest-debug internal] load build definition from Dockerfile.debug                                                                                                                                                  0.0s
 => => transferring dockerfile: 2.67kB                                                                                                                                                                                       0.0s
 => WARN: StageNameCasing: Stage name 'Debug' should be lowercase (line 34)                                                                                                                                                  0.0s
 => [dockertest-debug internal] load metadata for docker.io/torizon/debian:3.3.0-bookworm                                                                                                                                    1.6s
 => [dockertest-debug internal] load .dockerignore                                                                                                                                                                           0.0s
 => => transferring context: 56B                                                                                                                                                                                             0.0s
 => CACHED [dockertest-debug 1/7] FROM docker.io/torizon/debian:3.3.0-bookworm@sha256:0ce675b0a48960560e2add9299f60b025271caba22a371e05c1f28029b1f6b28                                                                       0.0s
 => [dockertest-debug internal] load build context                                                                                                                                                                           0.0s
 => => transferring context: 225B                                                                                                                                                                                            0.0s
 => ERROR [dockertest-debug 2/7] RUN apt-get -q -y update &&     apt-get -q -y install     openssl     openssh-server     rsync     file     curl     gdb &&     apt-get clean && apt-get autoremove &&     rm -rf /var/l  241.5s
------                                                                                                                                                                                                                            
 > [dockertest-debug 2/7] RUN apt-get -q -y update &&     apt-get -q -y install     openssl     openssh-server     rsync     file     curl     gdb &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists/*: 
20.79 Ign:1 https://feeds.toradex.com/debian/snapshots/20240116T145428Z testing InRelease
20.80 Ign:2 http://deb.debian.org/debian bookworm InRelease
40.82 Ign:3 http://deb.debian.org/debian bookworm-updates InRelease
41.81 Ign:1 https://feeds.toradex.com/debian/snapshots/20240116T145428Z testing InRelease
60.84 Ign:4 http://deb.debian.org/debian-security bookworm-security InRelease
63.83 Ign:1 https://feeds.toradex.com/debian/snapshots/20240116T145428Z testing InRelease
80.86 Ign:2 http://deb.debian.org/debian bookworm InRelease
87.86 Err:1 https://feeds.toradex.com/debian/snapshots/20240116T145428Z testing InRelease
87.86   Temporary failure resolving 'feeds.toradex.com'
100.9 Ign:3 http://deb.debian.org/debian bookworm-updates InRelease
120.9 Ign:4 http://deb.debian.org/debian-security bookworm-security InRelease
140.9 Ign:2 http://deb.debian.org/debian bookworm InRelease
160.9 Ign:3 http://deb.debian.org/debian bookworm-updates InRelease
181.0 Ign:4 http://deb.debian.org/debian-security bookworm-security InRelease
201.0 Err:2 http://deb.debian.org/debian bookworm InRelease
201.0   Temporary failure resolving 'deb.debian.org'
221.0 Err:3 http://deb.debian.org/debian bookworm-updates InRelease
221.0   Temporary failure resolving 'deb.debian.org'
241.0 Err:4 http://deb.debian.org/debian-security bookworm-security InRelease
241.0   Temporary failure resolving 'deb.debian.org'
241.1 Reading package lists...
241.2 W: Failed to fetch http://deb.debian.org/debian/dists/bookworm/InRelease  Temporary failure resolving 'deb.debian.org'
241.2 W: Failed to fetch http://deb.debian.org/debian/dists/bookworm-updates/InRelease  Temporary failure resolving 'deb.debian.org'
241.2 W: Failed to fetch http://deb.debian.org/debian-security/dists/bookworm-security/InRelease  Temporary failure resolving 'deb.debian.org'
241.2 W: Failed to fetch https://feeds.toradex.com/debian/snapshots/20240116T145428Z/dists/testing/InRelease  Temporary failure resolving 'feeds.toradex.com'
241.2 W: Some index files failed to download. They have been ignored, or old ones used instead.
241.4 Reading package lists...
241.5 Building dependency tree...
241.5 Reading state information...
241.5 Package openssh-server is not available, but is referred to by another package.
241.5 This may mean that the package is missing, has been obsoleted, or
241.5 is only available from another source
241.5 
241.5 E: Package 'openssh-server' has no installation candidate
241.5 E: Unable to locate package rsync
241.5 E: Unable to locate package file
241.5 E: Unable to locate package curl
241.5 E: Unable to locate package gdb
------
failed to solve: process "/bin/sh -c apt-get -q -y update &&     apt-get -q -y install     openssl     openssh-server     rsync     file     curl     gdb &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists/*" did not complet
e successfully: exit code: 100                                                                                                                                                                                                                          
 *  The terminal process "/usr/bin/bash '-c', 'DOCKER_HOST= docker compose build --pull --build-arg SSHUSERNAME=torizon --build-arg APP_ROOT=/home/torizon/app --build-arg IMAGE_ARCH=arm64 --build-arg SSH_DEBUG_PORT=2230 --build-arg GPU=-vivante doc
kertest-debug'" terminated with exit code: 17.                                                                                                                                                                                                          

So obviously no packages can be dowloaded during the docker build process on the module from the Debian or Torizon repos. Looks like a missing network connection.
When I connect to the module with a terminal there is no problem connecting to debian.org and downloading packages with wget.

What can I do now?

Regards,
Björn

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Björn,

The issue you’re encountering during the Docker build process, where the container cannot resolve domain names or download packages, typically indicates a problem with DNS settings or network connectivity from within the Docker environment. Given that you can connect to debian.org and download packages with wget directly on the module, this suggests that the base system’s network is configured correctly, but the Docker environment lacks the proper configuration to access external networks.

Here are a few steps to troubleshoot and potentially resolve this issue:

  1. Docker Network Configuration: Ensure that Docker is configured to use the correct network settings, including DNS. Docker usually inherits the DNS settings from the host, but it might be necessary to explicitly set these for Docker or the build process.

  2. Use the --network flag: When running the Docker build command, you can specify the network settings. Using --network=host might help if the default Docker network configuration is the issue. However, be aware that using the host network changes how the container accesses network resources.

  3. Check Docker DNS Settings: Check the DNS settings in the Docker daemon configuration. On Linux, this can be found in /etc/docker/daemon.json. You might need to add a DNS entry like "dns": ["8.8.8.8", "8.8.4.4"] to ensure Docker can resolve external domains.

  4. Build Context: Ensure that the Docker build context does not inadvertently include large amounts of unnecessary data. This is less likely the issue given the error messages, but it’s good practice to keep the build context minimal to speed up the build process.

  5. Temporary Network Issues: Although it seems unlikely given your description, temporary network issues could cause this problem. Retrying after some time might resolve the issue if it was a temporary DNS or network outage.

  6. Manual DNS Resolution Test: Inside a Docker container running on your development machine, try resolving domain names using tools like ping or nslookup to ensure that DNS resolution works as expected within Docker containers.

  7. Firewall or Security Software: Ensure that no firewall or security software on your development machine or network is blocking Docker’s access to the network. This might involve checking both local firewall rules and any network-wide security policies.

If after trying these steps the issue persists, it might be helpful to look into Docker’s and the host system’s logs for any network-related errors or warnings that could provide further insights into the problem.

Best regards,
Tor

Please, also check if these links can help you solve your problem:

Configure Build Environment for Torizon Containers | Toradex Developer Center.

Greetings @bgrunwald,

This is strange. First of all to clarify, these network connections are happening on your local machine not on the module. Our VSCode extension works by first building the container on the local machine then it transfers the complete container image to the module.

This means these network issues are happening in the context of your local machine. Could you give details on your local machine. Is it Linux? Windows with WSL?

Best Regards,
Jeremias

Hi Jeremias,
thanks for the clarification. I was looking at the wrong end :wink:
I am running Windows with WSL 2. It uses the Ubuntu distro and installed docker via its repo. During installation of the VS Code extension all necessary packages were properly installed, but I did not check the docker network yet. I just tried setting DNS in /etc/docker/daemon.json within WSL with no success.
What else can I do to analyze the situation? Thanks for your help.

Regards,
Björn

Maybe this is important as well:

Some steps before in the build process the container using Dockerfile.sdk is successfully built:

 *  Executing task in folder DockerTest: DOCKER_HOST= docker build --pull -f /home/sikora/DockerTest/Dockerfile.sdk /home/sikora/DockerTest -t cross-toolchain-arm64-dockertest --build-arg IMAGE_ARCH=arm64 --build-arg GPU=-vivante --build-arg APP_ROOT=/home/torizon/app 

[+] Building 0.5s (8/8) FINISHED                                                                                                                                                                                                         docker:default
 => [internal] load build definition from Dockerfile.sdk                                                                                                                                                                                           0.0s
 => => transferring dockerfile: 1.06kB                                                                                                                                                                                                             0.0s
 => [internal] load metadata for docker.io/torizon/debian-cross-toolchain-arm64:3.3.0-bookworm                                                                                                                                                     0.4s
 => [internal] load .dockerignore                                                                                                                                                                                                                  0.0s
 => => transferring context: 56B                                                                                                                                                                                                                   0.0s
 => [1/4] FROM docker.io/torizon/debian-cross-toolchain-arm64:3.3.0-bookworm@sha256:46b730261b75685dd8bd454f295114bc1dfcd85f6e8f077b97bb57d719f033fd                                                                                               0.0s
 => CACHED [2/4] RUN apt-get -q -y update &&     apt-get -q -y install     &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists/*                                                                                           0.0s
 => CACHED [3/4] RUN apt-get -q -y update &&     apt-get -q -y install     &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists/*                                                                                           0.0s
 => CACHED [4/4] WORKDIR /home/torizon/app                                                                                                                                                                                                         0.0s
 => exporting to image                                                                                                                                                                                                                             0.0s
 => => exporting layers                                                                                                                                                                                                                            0.0s
 => => writing image sha256:888236a30bf8c72d3680075276c82344b1704bc260fd02662a9c94039eac3524                                                                                                                                                       0.0s
 => => naming to docker.io/library/cross-toolchain-arm64-dockertest                                                                                                                                                                                0.0s

BTW: Is there a way to copy the full log from the terminal window in VSC? I can only select single steps and copy them one by one.

BTW: Is there a way to copy the full log from the terminal window in VSC? I can only select single steps and copy them one by one.

Shift-Right Click into terminal and choose “Select All”…

Now the full log, if it helps:

Container Runtime: docker
Run Arguments: --rm --privileged torizon/binfmt
Container Name: binfmt
Error response from daemon: No such container: binfmt
Container does not exist. Starting ...
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: pwsh -nop .conf/validateDepsRunning.ps1 


⚠️ VALIDATING ENVIRONMENT


✅ Environment is valid!

 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: bash -c [[ ! -z "192.168.x.x" ]] && true || false 

 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: bash -c [[ "aarch64" == "aarch64" ]] && true || false 

 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: sleep 1 

 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: sshpass -p $$$$$ scp -P 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /home/user/DockerTest/docker-compose.yml torizon@192.168.x.x:~/ 

Warning: Permanently added '192.168.x.x' (ED25519) to the list of known hosts.
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: DOCKER_HOST=192.168.x.x:2375 docker image prune -f --filter=dangling=true 

Total reclaimed space: 0B
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: if [ false == false ]; then DOCKER_HOST=192.168.x.x:2375 docker compose -p torizon down --remove-orphans ; fi 

Warning: No resource found to remove for project "torizon".
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: DOCKER_HOST= docker build --pull -f /home/user/DockerTest/Dockerfile.sdk /home/user/DockerTest -t cross-toolchain-arm64-dockertest --build-arg IMAGE_ARCH=arm64 --build-arg GPU=-vivante --build-arg APP_ROOT=/home/torizon/app 

[+] Building 1.1s (8/8) FINISHED                                                                                                                                                                                   docker:default
 => [internal] load build definition from Dockerfile.sdk                                                                                                                                                                     0.0s
 => => transferring dockerfile: 1.06kB                                                                                                                                                                                       0.0s
 => [internal] load metadata for docker.io/torizon/debian-cross-toolchain-arm64:3.3.0-bookworm                                                                                                                               1.0s
 => [internal] load .dockerignore                                                                                                                                                                                            0.0s
 => => transferring context: 56B                                                                                                                                                                                             0.0s
 => [1/4] FROM docker.io/torizon/debian-cross-toolchain-arm64:3.3.0-bookworm@sha256:46b730261b75685dd8bd454f295114bc1dfcd85f6e8f077b97bb57d719f033fd                                                                         0.0s
 => CACHED [2/4] RUN apt-get -q -y update &&     apt-get -q -y install     &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists/*                                                                     0.0s
 => CACHED [3/4] RUN apt-get -q -y update &&     apt-get -q -y install     &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists/*                                                                     0.0s
 => CACHED [4/4] WORKDIR /home/torizon/app                                                                                                                                                                                   0.0s
 => exporting to image                                                                                                                                                                                                       0.0s
 => => exporting layers                                                                                                                                                                                                      0.0s
 => => writing image sha256:888236a30bf8c72d3680075276c82344b1704bc260fd02662a9c94039eac3524                                                                                                                                 0.0s
 => => naming to docker.io/library/cross-toolchain-arm64-dockertest                                                                                                                                                          0.0s
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: make ARCH=arm64 makedir 

 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: DOCKER_HOST= docker run --rm -v /home/user/DockerTest:/home/torizon/app cross-toolchain-arm64-dockertest make ARCH=arm64 CC=aarch64-linux-gnu-g++ debug 

make: Nothing to be done for 'debug'.
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task in folder DockerTest: DOCKER_HOST= docker compose build --pull --build-arg SSHUSERNAME=torizon --build-arg APP_ROOT=/home/torizon/app --build-arg IMAGE_ARCH=arm64 --build-arg SSH_DEBUG_PORT=2230 --build-arg GPU=-vivante dockertest-debug 

WARN[0000] The "DOCKER_LOGIN" variable is not set. Defaulting to a blank string. 
[+] Building 242.6s (6/11)                                                                                                                                                                                         docker:default
 => [dockertest-debug internal] load build definition from Dockerfile.debug                                                                                                                                                  0.0s
 => => transferring dockerfile: 2.67kB                                                                                                                                                                                       0.0s
 => WARN: StageNameCasing: Stage name 'Debug' should be lowercase (line 34)                                                                                                                                                  0.0s
 => [dockertest-debug internal] load metadata for docker.io/torizon/debian:3.3.0-bookworm                                                                                                                                    0.9s
 => [dockertest-debug internal] load .dockerignore                                                                                                                                                                           0.0s
 => => transferring context: 56B                                                                                                                                                                                             0.0s
 => CACHED [dockertest-debug 1/7] FROM docker.io/torizon/debian:3.3.0-bookworm@sha256:0ce675b0a48960560e2add9299f60b025271caba22a371e05c1f28029b1f6b28                                                                       0.0s
 => [dockertest-debug internal] load build context                                                                                                                                                                           0.0s
 => => transferring context: 225B                                                                                                                                                                                            0.0s
 => ERROR [dockertest-debug 2/7] RUN apt-get -q -y update &&     apt-get -q -y install     openssl     openssh-server     rsync     file     curl     gdb &&     apt-get clean && apt-get autoremove &&     rm -rf /var/l  241.6s
------                                                                                                                                                                                                                            
 > [dockertest-debug 2/7] RUN apt-get -q -y update &&     apt-get -q -y install     openssl     openssh-server     rsync     file     curl     gdb &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists/*: 
20.81 Ign:1 https://feeds.toradex.com/debian/snapshots/20240116T145428Z testing InRelease                                                                                                                                         
20.81 Ign:2 http://deb.debian.org/debian bookworm InRelease                                                                                                                                                                       
40.84 Ign:3 http://deb.debian.org/debian bookworm-updates InRelease                                                                                                                                                               
41.83 Ign:1 https://feeds.toradex.com/debian/snapshots/20240116T145428Z testing InRelease                                                                                                                                         
60.86 Ign:4 http://deb.debian.org/debian-security bookworm-security InRelease
63.86 Ign:1 https://feeds.toradex.com/debian/snapshots/20240116T145428Z testing InRelease
80.88 Ign:2 http://deb.debian.org/debian bookworm InRelease
87.88 Err:1 https://feeds.toradex.com/debian/snapshots/20240116T145428Z testing InRelease
87.88   Temporary failure resolving 'feeds.toradex.com'
100.9 Ign:3 http://deb.debian.org/debian bookworm-updates InRelease
120.9 Ign:4 http://deb.debian.org/debian-security bookworm-security InRelease
140.9 Ign:2 http://deb.debian.org/debian bookworm InRelease
161.0 Ign:3 http://deb.debian.org/debian bookworm-updates InRelease
181.0 Ign:4 http://deb.debian.org/debian-security bookworm-security InRelease
201.0 Err:2 http://deb.debian.org/debian bookworm InRelease
201.0   Temporary failure resolving 'deb.debian.org'
221.0 Err:3 http://deb.debian.org/debian bookworm-updates InRelease
221.0   Temporary failure resolving 'deb.debian.org'
241.0 Err:4 http://deb.debian.org/debian-security bookworm-security InRelease
241.0   Temporary failure resolving 'deb.debian.org'
241.1 Reading package lists...
241.3 W: Failed to fetch http://deb.debian.org/debian/dists/bookworm/InRelease  Temporary failure resolving 'deb.debian.org'
241.3 W: Failed to fetch http://deb.debian.org/debian/dists/bookworm-updates/InRelease  Temporary failure resolving 'deb.debian.org'
241.3 W: Failed to fetch http://deb.debian.org/debian-security/dists/bookworm-security/InRelease  Temporary failure resolving 'deb.debian.org'
241.3 W: Failed to fetch https://feeds.toradex.com/debian/snapshots/20240116T145428Z/dists/testing/InRelease  Temporary failure resolving 'feeds.toradex.com'
241.3 W: Some index files failed to download. They have been ignored, or old ones used instead.
241.4 Reading package lists...
241.6 Building dependency tree...
241.6 Reading state information...
241.6 Package openssh-server is not available, but is referred to by another package.
241.6 This may mean that the package is missing, has been obsoleted, or
241.6 is only available from another source
241.6 
241.6 E: Package 'openssh-server' has no installation candidate
241.6 E: Unable to locate package rsync
241.6 E: Unable to locate package file
241.6 E: Unable to locate package curl
241.6 E: Unable to locate package gdb
------
failed to solve: process "/bin/sh -c apt-get -q -y update &&     apt-get -q -y install     openssl     openssh-server     rsync     file     curl     gdb &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists/*" did not complete successfully: exit code: 100

 *  The terminal process "/usr/bin/bash '-c', 'DOCKER_HOST= docker compose build --pull --build-arg SSHUSERNAME=torizon --build-arg APP_ROOT=/home/torizon/app --build-arg IMAGE_ARCH=arm64 --build-arg SSH_DEBUG_PORT=2230 --build-arg GPU=-vivante dockertest-debug'" terminated with exit code: 17. 
 *  Terminal will be reused by tasks, press any key to close it. 

I got a hint for my problem. When I run the command

TAG=arm64 LOCAL_REGISTRY=localhost docker compose build --pull --build-arg SSHUSERNAME=torizon --build-arg APP_ROOT=/home/torizon/app --build-arg IMAGE_ARCH=arm64 --build-arg SSH_DEBUG_PORT=2230 --build-arg GPU=-vivante dockertest-debug

within the WSL2 shell as a normal user, the image is properly built.
Running the same command as superuser it fails the same way as within VSC using the plugin. So it seems to me that the container is built with root privileges although it states in the Torizon docs that docker needs to run as a normal user within WSL: Install Docker Engine
Another hint that the plugin is using superuser for docker is that if I run docker ps as a normal user it shows no running containers whereas sudo docker ps shows running registry container.

So first question is the VSC plugin supposed to run docker as superuser? And if so, why does docker networking works as normal user but not as root?

So first question is the VSC plugin supposed to run docker as superuser? And if so, why does docker networking works as normal user but not as root?

This is very strange. I have a setup with VSCode and WSL 2 as well and this is not my observation. On my setup when the VSCode extension builds or runs a container I can see it as a normal non-root user in my WSL 2 distribution. The fact your setup is using a privileged user for this is odd and probably not correct.

I’m not sure yet what is causing this for you, I haven’t experienced or seen this before. Let me ask internally if anyone has an idea what might be happening here.

Best Regards,
Jeremias

After discussing internally the team thinks it may be possible Docker was installed or configured in a strange way on your development PC. Our VSCode extension does not run anything on your development PC with a privileged user. We’re also unable to reproduce this on our side as well, so it’s hard to say what caused this on your setup.

Could you try uninstalling and reinstalling Docker carefully. Then see if the issue still persists or not.

By the way when you install Docker are you installing the Docker engine in the WSL 2 environment, or are you installing Docker Desktop on your Windows environment?

Best Regards,
Jeremias

Thanks a million!

I am using Docker Engine in WSL 2. So I first reinstalled docker within WSL and faced the same network problem again.
Then I completely removed the WSL 2 Linux image and reinstalled everything from the scratch. Now all containers are started as the configured normal user and the networking issue is gone.

Something must have gone wrong during my first installation. Thanks again for your help!

Regards,

Björn

Glad to hear you were able to get this resolved.

Docker installation on Windows/WSL 2 can be finicky in my experience. Sometimes a reinstall is what’s needed to get everything back into a good state.

Best Regards,
Jeremias