0

I have a very simple Docker container that runs a bash shell script that returns something. My Dockerfile:

# Docker image to get stats from a rest interface using CURL and JSON parsing

FROM ubuntu

RUN apt-get update

# Install curl and jq, a lightweight command-line JSON processor
RUN apt-get install -y curl jq
COPY ./stats.sh /

# Make sure script has execute permissions for root
RUN chmod 500 stats.sh

# Define a custom entrypoint to execute stats commands easily within the container,
# using environment substitution and the like...
ENTRYPOINT ["/stats.sh"]
CMD ["info"]

The stats.sh looks like this:

#!/bin/bash

# ElasticSearch

## Get the total size of the elasticsearch DB in bytes
## Requires the elasticsearch container to be linked with alias 'elasticsearch'
function es_size() {
    local size=$(curl $ELASTICSEARCH_PORT_9200_TCP_ADDR:$ELASTICSEARCH_PORT_9200_TCP_PORT/_stats/_all 2>/dev/null|jq ._all.total.store.size_in_bytes)
    echo $size
}

if [[ "$1" == "info" ]]; then
    echo "Check stats.sh for available commands"
elif [[ "$1" == "es_size" ]]; then
    es_size
else
    echo "Unknown command: $@"
fi

So basically, I have a Docker container that I will run with --rm to exit immediately after running and returning the value I want. More precise, I run it from another shell script (in the host) with:

local size=$(docker run --name stats-es-size --rm --link $esName:elasticsearch $ENV_DOCKER_REST_STATS_IMAGE:$ENV_DOCKER_REST_STATS_VERSION es_size)

Now I'm running this periodically to gather statistics, once a minute. While it works well in general, I end up getting containers with status Dead about once a day.

Can anybody tell me what I might be doing wrong? Is there some problem with my approach or why do my containers die with a certain frequency?

mmey
  • 1,545
  • 16
  • 24
  • P.S. I'm using docker version 1.6.0 – mmey Jun 25 '15 at 19:38
  • possible duplicate of [Docker container with status "Dead" after consul healthcheck runs](http://stackoverflow.com/questions/30550472/docker-container-with-status-dead-after-consul-healthcheck-runs) – dnozay Jun 25 '15 at 19:45
  • I would suggest trying to extract logs from the container and debugging the issue. – dnozay Jun 25 '15 at 19:46
  • Hm, what logs exactly would you suggest that I extract from the container? As I said, the script runs once a minute (i.e. 1440 times a day) and fails maybe once a day (but that in a regular fashion). I haven't bothered investing too much time into debugging yet. I was hoping someone could spot a general problem in my approach... or are we just experiencing Docker bugs, as in your possible duplicate and in https://github.com/docker/docker/issues/9665...? – mmey Jun 29 '15 at 08:32
  • every time you get a status "dead" you could log them to a file, maybe a trend will appear. e.g. same time a cron restarts a service - i know some folks that have a cron to restart docker daemon once in a while. – dnozay Jun 29 '15 at 19:48
  • Thanks for the input. I'll see if I want to do that. I've checked the deamon logs, I'm getting the same "device or resource busy" error as in the possible dublicate you mentioned. I still feel like I have a pretty straightforward, simple container and don't see why docker would have problems deleting it. After all, I'm waiting for a simple script to run and return, doesn't seem too fancy... :-/ btw, I've updated to docker version 1.6.2 in the meantime, still same problem... – mmey Jun 30 '15 at 12:37
  • there are a lot of issues around `EBUSY` see https://github.com/docker/docker/issues/5684. – dnozay Jun 30 '15 at 15:55
  • Thanks for the input. Looks like Docker still suffers from a few "childhood" bugs. I'll keep an eye on it... – mmey Jul 01 '15 at 19:11

0 Answers0