How to update environment variables on running container without losing data?

I’ve created a traefik container to ingress the traffic to a containerized application hosted on docker instance. The traefik container was created via docker-compose, and it contains some environment variables which are required for TLS certificate renewal. The env var were expired few days ago. Now, I want to update the env var inside the “running traefik container” to get the certificate renewed.

What is the procedure to update the environment variables?. By doing so, will it create a fresh traefik container and the configuration changes I’ve done inside the container so far will be lost?

Docker instance is hosted on Ubuntu 20.04 LTS server.

You change the variable and run

docker compose up -d

You shouldn’t have any data in the container, only on volumes which would not be lost. Variables can be changed only by recreating the container, so yes, anything you saved on the container’s filesystem will be lost, but you can use docker cp to copy everything out and mount that into the container…

1 Like