Kyle Banks

Debugging Docker Containers on Elastic Beanstalk

Written by @kylewbanks on Jul 20, 2016.

While deploying Docker containers on Amazon’s Elastic Beanstalk is about as easy as it gets, it can be a little tricky to debug the container. For example, you may want to tail the logs, or open a shell inside the container to see what’s going on.

Elastic Beanstalk is great for the deployment portion, but I found little-to-no documentation on how to actually check on the container after SSH-ing into the host instance. There are some log files available in /var/log such as /var/log/eb-activity.log and /var/log/docker, but there is no readily available log files for your container with the default configuration.

Additionally, it doesn’t even seem at first glance like docker is running:

$ ssh -i /path/to/your.pem ec2-user@instance-ip
$ docker ps

ERROR: Cannot connect to the Docker daemon. Is the docker daemon running on this host?

The trick is that you have to switch to the root user first:

$ sudo su -

Now you’ll find that you’re able to execute Docker commands without error:

$ docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
63c291aedeaf        Image-Id            "/a/command"        18 hours ago        Up 18 hours         8080/tcp            distracted_hoover

Knowing the Container ID of our running container allows us to tail the logs:

$ docker logs -f <Container ID>

Additionally, we can open a bash shell inside the container and see what’s going on inside:

$ docker exec -it <Container ID> bash

Knowing these two commands, we can do just about any debugging we need with our container!

Let me know if this post was helpful on Twitter @kylewbanks or down below!