Junior — Middle
How can you view environment variables inside a running Docker container?
sobes.tech AI
Answer from AI
To view environment variables inside a running Docker container, you can execute the docker exec command, which runs a command inside the container. For example:
docker exec <container_id_or_name> printenv
This command will display all environment variables. You can also use:
docker exec <container_id_or_name> env
If you want to see a specific variable, such as PATH:
docker exec <container_id_or_name> printenv PATH
Alternatively, you can access the container with an interactive shell:
docker exec -it <container_id_or_name> /bin/sh
or
docker exec -it <container_id_or_name> /bin/bash
and then use the env or printenv command inside the container.