0

My nodejs/express application sends API calls from a server to a Portainer instance on a second, distant server. Portainer then creates/starts/stops/deletes docker containers on demand. Exactly as in Portainer's API docs, but using await/fetch. Works beautifully.

My docker containers use on their own env variables, set at the creation of the each container. Once the container is running though, changing any variables in the env seems difficult. From what I read, I understand I should destroy the container and recreate it with the updated env variables.

While according to Docker's API documentation some features of the container can be "updated" using and API call. Using a similar call to Portainer returns 200 (or "success"), but the container seems unaffected but the command:

const response = await fetch(
      `https://portainer.${url}/api/endpoints/1/docker/containers/${containerId}/update`,
      {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: `Bearer ${token}`,
        },
        body: JSON.stringify(containerConfig),
      },
      ...
)

Is there any documented or undocumented way to modify the env variables and restart the container without destroying and recreating it ?

Thanks, Lorenzo

Lorenzo Sandini
  • 117
  • 1
  • 8
  • In general in Unix you can't modify the environment of a process once it's been created, and this extends to Docker too. "You need to stop the process and run the command again" is entirely analagous to "you need to delete the conatiner and run a new one"; this is entirely routine. Also see [How to set an environment variable in a running docker container](https://stackoverflow.com/questions/27812548/how-to-set-an-environment-variable-in-a-running-docker-container) for further pure-Docker discussion. I don't know what Portainer's capabilities are here. – David Maze Jul 01 '23 at 16:36

0 Answers0