Skip to content

Wrap up

Mark Fernandes edited this page Sep 9, 2016 · 6 revisions

Housekeeping on your Docker server

'docker ps' shows containers running on your host
'docker stop [ID]' stops the execution of the container with the stated id.
'docker rm [ID]' removes the container matching id (can be a list of ids)
'docker rmi [ID]' removes pulled image id (only do this is space is a concern)
'docker stats ' (i.e. ‘top’ for docker containers)

Have trouble remembering those IDs or want to script them?

cid = $(docker run....)
docker kill $cid
docker rm $cid

Want to stop and remove all currently running containers?

docker stop $(docker ps -aq)
docker rm $(docker ps -aq)

Dockerfile tricks

  • Use && to combine command - this reduces the number of layers and can result in smaller images (downside file is not so readable
  • Use \ to continue long lines (just like Linux) which can improve readability when you have large lists of pre requisite packages
  • If you look at my Dockerfiles you will notice I prefix all apt-get installs with an apt-get to ensure ALL the packages get updated (this can be a downside of the layers) and I try and clear up temp & cache files to reduce the size of a layer which translates into a smaller container.
  • Spend some time examining other people's Dockerfiles on the Docker Hub and you will learn lots of tricks (even broken ones have value here).

Feedback form

Please leave constructive feedback here.
Thank you.