Learn Docker — 8 Docker Tips You Oughta Know

By now, most of the avid programmers would have known or used Docker, a container technology provides a self-contained execution environments that share the kernel of the host operating system, which provide an ease way to move to different environment. There are tons of sites to get started (the official site is a great way to learn more or for windows user). Here we will see about 8 Docker tips to make daily life with it ease. It’s not just about shortcut keys but using existing commands in which didn’t use.

8 Awesome Docker Tips

1. Using ‘Docker Compose’

Do you create a ‘shell’ and run each morning when starting your pc?
Do still running multiple containers one by one in the proper order?

Well there is something called ‘Docker Compose’ – It can run multiple containers, choose which one to start first and lot more in just a single YAML file. Every morning, all you need to do is run docker-compose start thats it! Lets ease the life!
Following is an example for running 2 containers, apache and mysql, by starting mysql container first.


Save this as ‘mywebapp.yml’ and just do ‘docker-compose up’ to start it.
Learn more about Docker Compose from https://docs.docker.com/compose/compose-file/compose-file-v2/

2) Use Docker Hub

There is an Docker image for most of things already there in Docker hub. Instead of recreating everything from scratch, all we can do is to run ‘docker pull…’ command. But my preference is always to use an Official Docker image so that it can be trusted for my projects.

Need mysql 5.7 and 5.5 version? just do ‘docker pull mysql:5.7’ and ‘docker pull mysql:5.5’ you will now have both images installed very easily in your machine. Now, all you need to is to mention the image name along with version in your docker-compose file to switch over. (one of the many uses of having Docker)
Some of the useful Docker images from hub”

1. https://hub.docker.com/_/nginx/
2. https://hub.docker.com/_/httpd/
3. https://hub.docker.com/_/mysql/
4. https://hub.docker.com/_/php/
5. https://hub.docker.com/_/composer/

3. Switching to Alpine

Even though the size of the Docker images are not huge compared to virtual machine which we use before (like Vagrant), sometimes, its still high. A Ubuntu base image can be around 200MB which is quite high. The problem with huge size is the docker build will be slow. The solution for this to choose an Alpine version of Docker – A minimal Docker image based on Alpine Linux with a complete package index and only 5 MB in size!

docker alpine
docker alpine


4. Restart Policy

Docker containers, once started will run until the process/command mentioned in the containers are completed and eventually will be stopped and status will be in ‘Exited’. What if you have to restart containers automatically on every exit? or restart only if there is an error? or restart n number of times? There are lot of solution like using Supervisord to handle this. But much more easier (but limited) way is to use the Docker –restart policy.

docker restart policy
docker restart policy


5. Clean Up

If you are using Docker for several months, chances are your system will be left with lot of junks. It can be dangling images, or unused memory, more like garbage collections. It can actually reduce few MB’s.

The reason for these dumps can happen whenever building images are abruptly stopped due to an error or containers are killed without stopping properly.

To solve this, there is ‘Docker Prune’

  • Allows cleaning by unused dangling images. (not all images)

  • It will remove all stopped containers (in case you have forgotten to give –rm when running)

  • Allows cleaning by unused dangling images

  • All networks not used by at least one container.

  • Does everything from 1 – 4


6. Filtering

Another effective use of Docker is using Filters. There are tons of filters provided by Docker (Checkout the reference section). Few of the useful filters are

  • Lists all container which are exited status
    • Other status filters values: created, restarting, running, removing, paused, exited and dead.

  • Lists all containers that use the latest ubuntu image
    • Other ancestor filters values, tags, image id

  • Lists all containers that mount a specific volume or have a volume mounted in a specific path


7. Docker Stats

Once you get your Docker build application to production, you outta know more about metrics like resource usages like memory etc. For this we have ‘docker stats’.

The above format is a customised one which will neatly display how much memory docker container is used. (running and stopped)

docker stats
docker stats


8. Docker Tips : Command Line

Few of the awesome command line tricks:

  • Remove stop containers

  • Remove dangling images

(or you can use docker prune) latest version

  • Get Docker container IP

  • Export & Import



Well, these covers most of them and I really hope these docker tips are useful to developers who are new and still learning about Docker. There are really tons of tips still out there and best place to learn more about these docker tips to start with Docker reference site.


Installing Docker For Windows 10

I just started another day to write some code and Aurelia Framework caught my eyes. There are several ways in which we can install but using Node and Webpack seems neater way. Also, I’m in much favour for writing programs in Linux rather in Windows (Windows 10 is awesome though!). Previously install dual boot of linux in my system but just thinking, why the hell i need a dual boot if only i need just for programming. Ta-da! There is Docker ofcourse and recent version of them even provides Docker for Windows 10 directly. So, here we are today going to see and installing docker for windows 10.

Installing Docker for Windows 10

There are ways in which you can install Docker for Windows

Pre requirements

  1. 64 bit Windows 10 Pro, Enterprise and Education
  2. The Hyper-V package (Virtual machine!)

If you have passed requirement no 1, lets started on 2. (else use Docker toolbox) Even though according Docker, “The Docker for Windows installer will enable it for you, if needed.”.

You have to enable one more thing for “Hyper-V” first, else you will get the below error message after installing docker.

Hardware-assisted virtualization and data execution protection must be enabled in the BIOS

1. How to Enable Virtualization in Windows 10:

This is a tricky part for beginners, but very simple one. You have enable it BIOS screen.

  1. Restart your system
  2. Proceed to BIOS page (F2 for ASUS)
  3. Search for Virtualization Technology and enable it
  4. Save and reboot

Thats it. For the next step.

2. How to Enable Hyper-V:

You can either let Docker do this or you can do it yourself (It’s always useful to learn it manually!)

  1. Enter Turn windows features on or off in Search
  2. Scroll and see Hyper-V and check it!
  3. Restart again!

Finally, all our pre requirements has been completed. Now, lets see how to install Docker for Windows 10.

3. Installing Docker

  1. Download the stable Docker for Windows
  2. https://download.docker.com/win/stable/InstallDocker.msi
  3. Follow the simple Wizard and Hit finish.
  4. Thats it, as simple as that.

Now let’s verify whether Docker is installed, go to Powershell and type docker --version. Did you get the below


You have successfully installed Docker in Windows 10, awesome!!!

4. Installing Ubuntu on Docker for Windows.

Next stop, let’s install Ubuntu in Docker to achieve our final goal

In powershell, give following command
$ docker run -it ubuntu bash


This will install ubuntu Docker Image in our Virtual Machine.
Now you are root user root@014150a01c9f:/# i.e. you are inside the Ubuntu Virtual Machine!
Type cat /etc/*release, you got the Ubuntu 16.04

Thats it!! We have installed Ubuntu 16.04 in Windows 10 Machine!

Hopefully this will give you the way to harness the power of both Ubuntu and Windows in a single machine! Stay tuned for more about using Docker