Cleaning up while playing with Dockerfiles

/, Short Notice/Cleaning up while playing with Dockerfiles

Cleaning up while playing with Dockerfiles

As I play around a lot with Docker these days, I recognized how fast one is running out of hard disk space while building and running a lot of Dockerfiles. When one starts with using Dockerfiles there is a lot of trail and error until the expected services are running properly.

In my case, I created a very simple bash script, that I copy into the folder where I create my Dockerfile.

For instance, I have the following setup, where I create and host my Dockerfiles:

For each Dockerfile I have a script, called d.sh, that can build and run the docker files for me, while also cleaning all data up. It is important to know, that this script is stopping and deleting the other docker container instances! This makes a lot of sense, when you are tinkering around with specific setting in your Dockerfile but always like to use the same port as before.

The d.sh Script can be called with two parameters:

  1. The name of the Docker Container that will be used while creating the container.
    If no name is given, the container is named „ramdom-
    [a random number]“
  2. The Ports that should be exposed to the outer world (aka host machine).

While the script is running, all other docker containers are stopped and deleted (line 12-13). There is also a parameter to delete the created images (line 14), but this one is currently disabled. Instead of „ubuntu|test“ you can add there other names of images you do not like to remove while running the script.

  1. To stop all currently running docker files, one can call:
  2. To remove all created docker container files, one can call:
  3. To remove all created docker images, one can call: This command will delete all images, but not „ubuntu“ and „test“. You can add additional ones here.

After the building and running process it will list all currently running docker containers.

When you call the script without any parameters it will look like: When giving the name and a port: When giving just the name: Please use this script at your own risk, as I just wrote, it will delete docker files from your server, when not commenting out!
By | 2017-01-29T10:32:50+00:00 Juni 14th, 2014|DevOps - Server and Technologies and virtualization, Short Notice|0 Comments

Share This Story, Choose Your Platform!

Leave A Comment