0

Is it possible to add environment variables to a crashed container?

I tried

$ docker start --env MYVAR='value' <container_id>
$ docker exec --env MYVAR='value' <container_id> entrypoint.sh

But it didn't work

agusgambina
  • 6,229
  • 14
  • 54
  • 94
  • 1
    the question seems to be a bit abstract, but would https://stackoverflow.com/questions/34051747/get-environment-variable-from-docker-container/34052766 help you find some soultion? – Sunil Kumar Dec 29 '20 at 16:25

2 Answers2

2

You can't change environment variables on a container (or any other process) after it's been created.

I wouldn't bother trying to recover a container that's exited. docker rm it and docker run a new one. When you do docker run the new container, you can add or change environment variables as needed.

David Maze
  • 130,717
  • 29
  • 175
  • 215
0

docker start doesn't have an --env option, it only starts a stopped container.

docker exec does allow setting environment variables when running a command on your container using the --env option.

Note that environment variables are also set when calling docker run to create the container with the --env option.

Alvaro Flaño Larrondo
  • 5,516
  • 2
  • 27
  • 46