duality_
duality_

Reputation: 18786

Fig: how do I run commands on an existing container?

I have two containers running with fig up: web and db. I'd like to get some info about the environment where the web container is running: what env variables are set, read some logs that the web server has written, etc.

I know that containers are a bit like processes and you don't "log into" processes, but they're also in a way similar to VMs and you do log into them...

How can I achieve that?

Upvotes: 0

Views: 5332

Answers (2)

mpaf
mpaf

Reputation: 6797

first you want to list your running containers:

docker ps

Then you can run a bash shell inside your running container using its ID or name:

docker exec -i -t 665b4a1e17b6 bash
docker exec -i -t container_name bash

Upvotes: 4

joh.scheuer
joh.scheuer

Reputation: 586

If you use Docker v.1.3.3+ you can use Docker exec to execute commands in your container. To get all env variables you can simply execute:

sudo docker exec [container ID or name] printenv

To read logs that are written to STDOUT and STDERR you can use Docker logs.

Upvotes: 2

Related Questions