'Find out value of environment variables being passed to container by docker-compose

I'm troubleshooting a service that's failing to start because of an environment variable issue. I'd like to check out what the environment variables look like from the inside of the container. Is there a command I can pass in my docker-compose.yaml so that instead of starting the service it prints the relevant environment variable to standard output and exits?



Solution 1:[1]

Try this:

docker-compose run rabbitmq env

This will print all the environment variables for rabbitmq service.

Solution 2:[2]

Get the container ID with docker ps.

Then execute a shell for the running rabbitmq container by running docker exec command with the container id for your rabbitmq container.

Once you are on the rabbitmq container, you can echo out the value of any environment variable like you would on any other linux system. e.g. if you declared ENV DEBUG=true at image build time, then is should be able to retrieve that value with echo $DEBUG in the container. Furthermore, once you are in the container, you can poke around the log files for more investigation.

Solution 3:[3]

As others have said, first get the container ID with docker ps. When you have done that, view all the properties with docker inspect <id> and you will see something like:

[
    {
        ...
        "Config": {
            ...
            "Env": [
                "ASPNETCORE_URLS=http://+:80",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "DOTNET_RUNNING_IN_CONTAINER=true",
                "DOTNET_VERSION=6.0.1",
                "ASPNET_VERSION=6.0.1",
                "Logging__Console__FormatterName=Json"
            ],
            ...
        }
    }
]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Suraj Gautam
Solution 2 aidanmelen
Solution 3 Fredrik C