From 4e1261a0bedf31ee76024739c918948b069fab7d Mon Sep 17 00:00:00 2001 From: "Ted M. Young" Date: Tue, 7 Jul 2015 11:42:35 -0700 Subject: [PATCH] Using Alpine Linux base image and .dockerignore file to make Docker image even smaller. --- .dockerignore | 3 +++ Dockerfile | 19 +++++++++---------- README.md | 23 +++++++++++++++-------- 3 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a65bf5c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git/ +debian/ + diff --git a/Dockerfile b/Dockerfile index 378b1e0..677ffe6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,16 @@ -FROM debian:jessie +FROM gliderlabs/alpine:3.2 ENV DOCKER_VERSION 1.6.2 -RUN apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y python-minimal \ - && apt-get clean \ - && rm -rf /var/apt/lists/* +# We get curl so that we can avoid a separate ADD to fetch the Docker binary, and then we'll remove it +RUN apk --update add bash curl python \ + && curl -s https://get.docker.io/builds/Linux/x86_64/docker-${DOCKER_VERSION} > /bin/docker \ + && chmod +x /bin/docker \ + && apk del curl \ + && rm -rf /var/cache/apk/* -ADD https://get.docker.com/builds/Linux/x86_64/docker-${DOCKER_VERSION} /usr/local/bin/docker -RUN chmod +x /usr/local/bin/docker - -ADD docker-gc /docker-gc +COPY ./docker-gc /docker-gc VOLUME /var/lib/docker-gc -CMD ["/docker-gc"] \ No newline at end of file +CMD ["/docker-gc"] diff --git a/README.md b/README.md index efe146f..75f2eb4 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,20 @@ docker-gc ========= -A simple docker container and image garbage collection script. +A simple Docker container and image garbage collection script. * Containers that exited more than an hour ago are removed. * Images that don't belong to any remaining container after that are removed. Although docker normally prevents removal of images that are in use by -containers, we take extra care to not remove any image tags (e.g. ubuntu:14.04, +containers, we take extra care to not remove any image tags (e.g., ubuntu:14.04, busybox, etc) that are in use by containers. A naive `docker rmi $(docker images -q)` will leave images stripped of all tags, forcing docker to re-pull the repositories when starting new containers even though the images themselves are still on disk. -This script is intended to be run as a cron job. +This script is intended to be run as a cron job. You can also run it as a Docker +container (see below). Building -------- @@ -35,8 +36,8 @@ Installing $ dpkg -i ../docker-gc_0.0.3_all.deb ``` -This installs the `docker-gc` script into `/usr/sbin` and drops a `docker-gc` cron -file into `/etc/cron.hourly/`. +This installs the `docker-gc` script into `/usr/sbin` and drops a `docker-gc` +cron file into `/etc/cron.hourly/`. Usage @@ -69,14 +70,20 @@ spotify/cassandra:latest Running as a Docker Image ------------------------- -A Dockerfile is provided as an alternative to a local installation. By default the container will start up, run a single garbage collection, and shut down. +A Dockerfile is provided as an alternative to a local installation. By default +the container will start up, run a single garbage collection, and shut down. + +### Build the Docker Image ```sh docker build -t spotify/docker-gc . ``` -The docker-gc container requires access to the docker socket in order to function. +### Running as a Docker Container + +The docker-gc container requires access to the docker socket in order to +function, so you need to map it when running, e.g.: ```sh docker run --rm -v /var/run/docker.sock:/var/run/docker.sock spotify/docker-gc -``` \ No newline at end of file +```