Apt-add-repository not updating sources list on build

When attempting a build, the apt-add-repository command appears to execute, but the new repository is not showing up in the updated list and the app to be installed isn’t being found. When the exact same command is run in an interactive session with a container using the image (with the single command commented so the build will complete), the sources list is being updated correctly and the install works normally.

NOTE - where {URL} appears below is
http://deb.debian.org/debian
It has been replaced due to form filtering rules.

In Dockerfile -

RUN dpkg --add-architecture i386 \
        && add-apt-repository -y -n -U {URL} -c contrib -c non-free \
        && apt update \
        && apt install -y steamcmd

And the output -


[5/6] RUN dpkg --add-architecture i386       && add-apt-repository -y -n -U {URL} -c contrib -c non-free      && apt update   && apt install -y steamcmd:
0.310 Repository: 'deb {URL} bookworm non-free contrib'
0.310 Description:
0.310 Archive for codename: bookworm components: non-free,contrib
0.310 More info: {URL}
0.310 Adding repository.
0.310 Adding deb entry to /etc/apt/sources.list.d/archive_uri-http_deb_debian_org_debian-bookworm.list
0.310 Adding disabled deb-src entry to /etc/apt/sources.list.d/archive_uri-http_deb_debian_org_debian-bookworm.list
0.322
0.322 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
0.322
0.361 Hit:1 {URL} stable InRelease
0.361 Hit:2 {URL} stable-updates InRelease
0.361 Hit:3 {URL}-security stable-security InRelease
0.663 Reading package lists...
1.264 Building dependency tree...
1.414 Reading state information...
1.431 All packages are up to date.
1.437
1.437 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
1.437
1.438 Reading package lists...
2.029 Building dependency tree...
2.181 Reading state information...
2.187 E: Unable to locate package steamcmd

Executed in the container

dpkg --add-architecture i386 && add-apt-repository -y -n -U {URL} -c contrib -c non-free && apt update && apt install -y steamcmd

Output

*Repository: 'deb {URL} bookworm contrib non-free'*
*Description:*
*Archive for codename: bookworm components: contrib,non-free*
*More info: {URL}*
*Adding repository.*
*Adding deb entry to /etc/apt/sources.list.d/archive_uri-http_deb_debian_org_debian-bookworm.list*
*Adding disabled deb-src entry to /etc/apt/sources.list.d/archive_uri-http_deb_debian_org_debian-bookworm.list*
*Get:1 {URL} bookworm InRelease [151 kB]*
*Hit:2 {URL} stable InRelease*
*Hit:3 {URL} stable-updates InRelease*
*Hit:4 {URL}-security stable-security InRelease*
*Get:5 {URL} bookworm/contrib i386 Packages [46.6 kB]*
*Get:6 {URL} bookworm/non-free amd64 Packages [97.3 kB]*
*Get:7 {URL} bookworm/contrib amd64 Packages [54.1 kB]*
*Get:8 {URL} bookworm/non-free i386 Packages [73.4 kB]*
*Fetched 435 kB in 0s (1945 kB/s)*
*Reading package lists... Done*
*Building dependency tree... Done*
*Reading state information... Done*
*All packages are up to date.*
*Reading package lists... Done*
*Building dependency tree... Done*
*Reading state information... Done*
*The following additional packages will be installed:*
*  gcc-12-base:i386 libc6:i386 libgcc-s1:i386 libstdc++6:i386*

…And the app installs correctly.

To make the image build, the only change I am making is commenting out the last “apt install” command. From the console logs, it looks like the issue is in the apt-add-repository command, as I’m only seeing the default 3 Hit messages after adding the repository, and not the additional Get messages. This “RUN dpkg” command string is the last thing being done in the Dockerfile other than setting the WORKDIR. I believe I’ve removed every possible variable at this point other than the command being run during build rather than being run in the container.

You probably ran the command twice because whenever I ran it in a test container it fails first even interactively. The repo list file remains empty until running add-apt-repository the second time. It must be something APT or Debian-related. I’m not exactly sure, but I would not use add-apt-repository in a script. You probably had to install dependencies just for this when you can simply create your repository list file and copy it to /etc/apt/sources.list.d/

If you use code blocks, it shouldn’t happen. Formatting guide: How to format your forum posts

I added codeblocks to your post to make it more readable, but I didn’t fix the URLs

Thank you very much for the formatting fix, I’m clearly quite new.

"You probably ran the command twice because whenever I ran it in a test container it fails first even interactively. "

OK, that’s bizarre. I did have to add apt-utils and software-properties-common in order for the add-apt-repository to work at all (that’s happening earlier in the Dockerfile). But I didn’t have the issue of it ever not working first try in a fresh container. Editing the sources files directly was going to be my fallback if this didn’t work. I was trying to avoid that to keep things tidy and a bit more update/future proofed.

Was it the add-apt-repository command that you wound up running twice? If so, I may try doing that in the build script and see what happens.

When you work with containers, it’s best if you don’t rely only on commands you used before. You will want to keep the image as small as possible and you will not want to add any dependency that is not necessary for running the process for which you create the container. Otherwise you can add unecessary vulnerabilities as well. Even if you install something when building the image, if it is not required to run the process, you should immediately delete it in the same RUN instruction. There is no other way to completely delete it and the image will be just bigger.

Yes. But I ran it second time when the whole chain of commands ran already, if it matters.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.