Skip to content

Instantly share code, notes, and snippets.

@gerhard
Last active December 23, 2015 12:39
Show Gist options
  • Save gerhard/6636488 to your computer and use it in GitHub Desktop.
Save gerhard/6636488 to your computer and use it in GitHub Desktop.
Docker-fu

Remove all docker containers older than 7 days:

docker ps -a | awk '/[^1-7] days/ { system("docker rm "$1) }'

Remove docker images without a tag:

docker images | awk '/none/ { system("docker rmi "$3) }'

Build docker container part of Jenkins build:

app=$JOB_NAME
branch=$(echo $GIT_BRANCH | cut -d/ -f 2)

container_id=$(docker build -t $app:$branch $WORKSPACE)

App Dockerfile sample:

FROM howareyou/ruby_2.0.0-p247

ENV HOME /root
ENV PATH /usr/local/lib/2.0.0-p247/bin:$PATH
ENV SERVICE snomed

RUN mkdir -p /var/apps
ADD ./ /var/apps/$SERVICE
RUN rm -fr /var/apps/$SERVICE/.git
RUN cd /var/apps/$SERVICE && bundle install --local
RUN cd /var/apps/$SERVICE && bin/test

WORKDIR /var/apps/$SERVICE
CMD bundle exec foreman start

DOCKER GOTCHAS

  • ADD command is not cached. Any command following it won't be cached either.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment