Saturday, 25 June 2016

Manage Docker images on local disk

Docker is very powerful containerization technique, and it is becoming famous in short time.
People are adapting and containerizing their applications for deployment.

Soon container become very heavy and consume too much of disk space, If you do not delete old images and layers you may soon run out of disk space.
Here i am trying to cover the ways to regain the disk space consumed by docker images.
  • Moving docker filesystem to bigger mount point.
Usually docker keeps all temporary files related to image building and layers at /var/lib/docker
This path is local to the system usually at root partition "/".
You can mount a bigger disk space and move the content of /var/lib/docker to the new mount location and make sym link. 
This way even docker images occupy space, will not affect  your system as it will be using some other mount location.

  • Remove Old docker images
Here are few ways to remove old and unused docker images
  • Removing stopped container
docker ps -a | grep Exited | awk '{print $1}' | xargs docker rm

Authentication Error while pulling images via docker-maven-plugin

docker-maven-plugin is the great plugin provided by spotify to build docker image during maven build.

There is very strange error or behaviour I have seen during the image creation.
Plugin expects that image which Dockerfile is pulling needs to be passed with username and password, which should not an essential parameter as most of the images does not need any auth to be downloaded. 

You may see this error

[INFO] Building image your-application:0.0.3
Step 1 : FROM ubunt:latest
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] your-application..................................... FAILUER [  3.619 s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 39.938 s (Wall Clock)
[INFO] Finished at: 2016-06-25T16:26:06+00:00
[INFO] Final Memory: 65M/1216M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.3.7:build (default) on project 
your-application: Exception caught: Get 
unauthorized: incorrect username or password -> [Help 1]