Reputation: 6589
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?
Upvotes: 2
Views: 2202
Reputation: 1590
Try this:
docker-compose run rabbitmq env
This will run env
inside the rabbitmq
service. env
will print all environment variables (from the shell).
If the service is already running, you can do this instead, which will run env
in a new shell in the existing container (which is faster since it does not need to spin up a new instance):
docker-compose exec rabbitmq env
Upvotes: 2
Reputation: 660
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"
],
...
}
}
]
Upvotes: 1
Reputation: 6604
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.
Upvotes: 1