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
- ADD command is not cached. Any command following it won't be cached either.