# Fix "apt-key: not found" and "apt-key is deprecated" in a Dockerfile

An agent replaces each apt-key add in your Dockerfile with a keyring file and a signed-by source entry, then builds the image to prove the packages still install.

[Run this on Rush](https://cloud.getrush.ai/run/fix-apt-key-not-found/docker/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

`apt-key add` put a vendor's signing key into one keyring that apt trusted for every repository on the system. Debian and Ubuntu deprecated the command, and for a few releases a Dockerfile that piped a key into it printed `Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead`. Debian 13 no longer ships the command, so the same line now stops the build with `/bin/sh: 1: apt-key: not found`. The replacement is two small changes per repository: save the key as its own file, and name that file in the source entry with `signed-by`, so the key is trusted for that one repository only. The agent makes those changes and then builds the image, because a Dockerfile this old tends to have a second problem behind the first.

guilhermecgs/ir, a Brazilian tax report tool that scrapes a brokerage site with Selenium, has the line nearly everyone copied: `RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -`, followed by an `echo` that appends a `deb [arch=amd64] ...` entry to `/etc/apt/sources.list.d/google-chrome.list`. The base is `FROM python:3.10`, a tag that names no Debian release. The image therefore follows whatever release the tag is built on, and a Dockerfile nobody edited starts failing when that moves to one without `apt-key`. The agent writes the key to `/etc/apt/keyrings/google-chrome.asc` and adds `signed-by=/etc/apt/keyrings/google-chrome.asc` inside the entry's brackets. The published key is ASCII-armoured, and apt reads an armoured key from a file ending in `.asc`, so no `gpg --dearmor` step or extra package is needed.

The sandbox has no Docker, so the agent installs it first with `sudo apt-get install -y docker.io` and starts `dockerd`, then runs `docker build`. With the key fixed, the next step to look at is the driver install. The Dockerfile downloads `chromedriver_linux64.zip` for whatever version `chromedriver.storage.googleapis.com/LATEST_RELEASE` returns. That endpoint stopped receiving new versions at 114, while `google-chrome-stable` installs the current browser, so the image ends up with a browser and a driver many versions apart. `requirements.txt` adds a third opinion, pinning `chromedriver-binary==123.0.6295.0.0` beside `selenium==4.23.1`, a Selenium new enough to fetch a matching driver by itself.

The agent fixes what the task names and proves the rest. It builds the image, runs `google-chrome --version` and `chromedriver --version` inside it and puts the two outputs in the pull request. It proposes, as a separate commit, removing the manual driver download so Selenium's own driver management is the single source, and pinning the base image to a named Debian release so the next surprise is a choice. It leaves `.gitlab-ci.yml`, which builds and pushes this image on every push, as it is.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "This Dockerfile fails to build with \"/bin/sh: 1: apt-key: not found\", or prints \"Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead\". Find every use of apt-key in Dockerfiles, compose files, shell scripts and CI configuration: apt-key add, apt-key adv --keyserver, and add-apt-repository calls that rely on it. For each, save the key as its own file under /etc/apt/keyrings (create the directory if the base image lacks it) and add signed-by=<that file> to the matching sources entry, keeping any existing options such as arch. If the key is ASCII-armoured, store it with an .asc extension and do not add gnupg just to dearmor it; if it comes from a keyserver, fetch it over HTTPS by full fingerprint instead and state the fingerprint. Keep each key scoped to its own repository; never write to /etc/apt/trusted.gpg.d. Do not change which packages are installed. Then build every image: the sandbox has no Docker, so install docker.io with apt-get and start dockerd first. Show the full build output. Inside the built image, run apt-get update and confirm there are no signature warnings, and print the installed version of each package that came from a third-party repository. If the base image tag does not name a distribution release, report which release it resolved to and propose a pinned tag in a separate commit. Report any other step that fails or installs mismatched versions (for example a browser and its driver), with the commands that show it, and propose a fix in a separate commit without mixing it into the apt-key change. Open a pull request with the list of keys, their fingerprints, the commands and their output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request whose first commit touches only the key handling: for the Dockerfile above, the `apt-key add` line becomes a download to a file under `/etc/apt/keyrings`, and the `echo` line gains a `signed-by` option. The description lists each key with its fingerprint and the repository it is now tied to, and includes the `docker build` output up to the final image id and an `apt-get update` from inside the image with no `NO_PUBKEY` or signature warnings.

Further commits are separate and optional: the pinned base image tag, and the driver cleanup with the two version strings that justify it. A reviewer compares the fingerprint in the description with the one the vendor publishes, since the old line trusted whatever the URL returned and the new one should not be weaker than that. They check that `signed-by` sits inside the same brackets as `arch=amd64`, because a second pair of brackets is a syntax error apt reports only at update time. And they decide whether to take the base image pin, which trades automatic security updates of the tag for builds that do not change underneath them.

## Run it on every failed image build

A Dockerfile on a floating base tag breaks without a commit, so the first sign is a scheduled or push-triggered build going red. For a repository whose image is built by GitHub Actions, add an automation to the Project in the console with the prompt above and a `github` trigger on `workflow_run.failure`. Rush starts a run and puts the event after the saved prompt. Tell the agent in the prompt to read the failed job's log first and to stop with a one-line answer unless it contains `apt-key`.

The example repository builds on GitLab, which does not send GitHub events. There a job that runs when the pipeline fails can call a `webhook` trigger on the same automation: a `curl` to the trigger's URL with `Authorization: Bearer` and the secret the console showed when the trigger was created, held as a masked CI variable, and the failing job's name and log tail as the body. The body, up to 64 KB, becomes the event text. Sending the pipeline id in an `Idempotency-Key` header on that trigger call keeps a retried job from starting a second run.

## Why run it on Rush?

A Dockerfile change is proved by a build from an empty cache. Developer machines rarely have one: layers from last month's build are still there, and a cached `apt-key` layer from an older base image makes a broken Dockerfile build fine locally while CI fails. The agent starts its own Docker daemon in a sandbox that has never built this image, so every layer is pulled and executed, and the full build log is kept in the session transcript.

Images like this one are large, with a browser, a driver and a scientific Python stack, and building them twice to compare a pinned base with a floating one ties up a laptop and its disk. The sandbox absorbs that. It also lets the agent run the built container and execute version checks inside it, so the report that the browser and driver disagree comes from the image itself.

## Frequently asked questions

### What is the replacement for apt-key add?

Download the key to its own file, conventionally under `/etc/apt/keyrings`, and reference it from the source entry: `deb [signed-by=/etc/apt/keyrings/vendor.asc] https://... stable main`. An ASCII-armoured key can be stored as `.asc` unchanged; a binary key uses `.gpg`. Nothing is added to the global trusted keyring.

### Why did my build break when I changed nothing?

Because the base image changed. A tag such as `python:3.10` or `node:20` follows the current Debian release, and when that release drops a tool, every Dockerfile that used it fails on its next uncached build. Pinning the release in the tag, for example with a `-bookworm` suffix, makes that an upgrade you choose.

### Can I just install apt-key or copy the key into trusted.gpg.d?

On a release that removed it, the command is gone from apt itself, so there is nothing to install. Copying the key into `/etc/apt/trusted.gpg.d` still works and keeps the old weakness: that key is then trusted to sign packages from any repository. The `signed-by` form limits each key to its own repository, which is why the agent uses it.

### Does this apply to apt-key adv --keyserver too?

Yes, and it needs one more step, because there is no key URL in the Dockerfile to reuse. The agent fetches the key over HTTPS by its full fingerprint, stores it as a keyring file and records the fingerprint in the pull request so you can verify it against the vendor's documentation.

## More Docker jobs

- [Fix "The repository 'http://deb.debian.org/debian buster Release' does not have a Release file" in a Docker build](https://getrush.ai/run/fix-debian-buster-release-file-missing/docker/)
- [Fix a Broken Docker Build](https://getrush.ai/run/fix-docker-build/docker/)
- [Fix "error: externally-managed-environment" in a Docker Build](https://getrush.ai/run/fix-externally-managed-environment/docker/)

## More jobs like this: Fix a bug from an alert

- [Fix "PytestDeprecationWarning: The configuration option asyncio_default_fixture_loop_scope is unset"](https://getrush.ai/run/fix-asyncio-default-fixture-loop-scope-unset-warning/pytest-asyncio/)
- [Fix "TypeError: As of 3.10, the *loop* parameter was removed from Lock()" in asyncio](https://getrush.ai/run/fix-asyncio-loop-parameter-removed/asyncio/)
- [Fix "AttributeError: module 'base64' has no attribute 'encodestring'" in Python 3.9+](https://getrush.ai/run/fix-base64-encodestring-attribute-error/base64/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
