# Debugging

## AWS instances with docker are killed

When we want find out why an ec2 instance was killed, we need to first check if docker container is present. We need to use `-a` flag to tell docker to return also containers that are not running.

```
$ docker ps -a
CONTAINER ID        IMAGE          COMMAND                  CREATED             STATUS                     PORTS               NAMES
ba5925ec4a87        myservice...   "/bin/sh -c 'node ..."   6 minutes ago       Exited (1) 5 minutes ago                       myservice
```

Then we want to use name of the service and get logs.

```
$ docker logs myservice
...logs...
```

## See how docker instances were started

```
$ docker inspect -f "{{.Name}} {{.Config.Cmd}}" $(docker ps -a -q)
/my-service [/bin/sh -c pm2-docker -i max app.js]
/logrotate [cron]
/logs [/bin/sh -c exec fluentd -c /fluentd/etc/${FLUENTD_CONF} -p /fluentd/plugins $FLUENTD_OPT]
```

Or more standard command that print out all data, without shortening it.

```
$ docker ps -a --no-trunc
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ondrej-kvasnovsky-2.gitbook.io/docker-handbook/debugging.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
