Print all env variables by specifying a docker container name:
docker exec <container-name> /bin/sh -c 'printenv'
Print all env variables by specifying a docker service name:
docker-compose exec <service-name> /bin/sh -c 'printenv'
Print a specific variable (PATH) by using docker container name:
docker exec <container-name> /bin/sh -c 'printenv' | grep '^PATH='
gives:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Print a specific variable value (PATH) by using docker container name:
docker exec <container-name> /bin/sh -c 'printenv' | grep '^PATH=' | cut -d= -f2-
gives:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Same examples as above but for the docker service name:
Specific env variable:
docker-compose exec <service-name> /bin/sh -c 'printenv' | grep '^PATH='
Specific env variable value:
docker-compose exec <service-name> /bin/sh -c 'printenv' | grep '^PATH=' | cut -d= -f2-