Docker does not support a direct method for updating environment variables for a running container. This is something you can not call “a bug” because it is consistent with the immutable way Docker runs application. For this reason, the common way to update an environment variable is to re-create the container from the image. Sometimes this can not be done because your container has a state that must be preserved, especially if you are hacking on your machine. If you need to update them, three steps are required. Since I have to do this from time to time, I decided to write this note.
1. Find the container id
The first thing to do is to find the container ID you want tu update.
Use docker ps with a proper format to show the name and the corresponding ID of the container.
$ docker ps -a --format="table {{.Names}}\t{{.Image}}\t{{.ID}}"
NAMES IMAGE CONTAINER ID
freshrss freshrss:latest 23529b153d19
wonderful_bassi hello-world 9ad09ceb1076
2. Find the corresponding config file
Once you have the ID, you need to find the config file for that container.
Docker containers’ config files can be located in two places.
If you are running Docker as a daemon, the used path is (usually) /var/lib/docker/containers/:
/var/lib/docker/containers/[container-id]/config.v2.json
Otherwise, if you are running Docker in rootless mode the directory is located in your home ~/.local/share/docker/containers/:
~/.local/share/docker/containers/[container-id]/config.v2.json
Check the existence of the config.v2.json inside the folder named with the full container ID.
In this case the short ID listed in the shell is
23529b153d19but the full one is23529b153d19921f76e1bf38ce4ad776ad36ba138d74c1cb262a0fc42c0162de.
Paste the initial part of the ID you got from docker ps and let your shell autocompletion do the rest.
3. Edit the file
Before proceeding with the file edit, be sure to stop the docker daemon (and container - if live-restore is used).
Open the config.v2.json file and look for the Config.Env section.
Once located add, remove or update as many variables you want.
Below, an excerpt from a config.v2.json file.
{
"StreamConfig": {},
"State": {/*...*/},
"ID": "23529b153d19921f76e1bf38ce4ad776ad36ba138d74c1cb262a0fc42c0162de",
"Created": "2026-05-10T15:30:50.616310302Z",
"Managed": false,
"Path": "./Docker/entrypoint.sh",
"Args": [/**/],
"Config": {
"Env": [
"TZ=Europe/Rome",
"CRON_MIN=1,31",
"TRUSTED_PROXY=172.16.0.1/12 192.168.0.1/16",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
]
},
/* more properties...*/
}
After the file has been edited, save it and restart the Docker daemon with the changed container with docker start [container name|id].
Now the running container will have updated environment variables.