What is Docker?

Without going into the details of Linux I’ll try and explain Docker in a few lines, this won’t be a long post.

  • Docker is a tool that allows you to spin up containers within seconds.
  • Containers can be thought of as Virtual Machines but much more lightweight and portable. They are basically miniature operating systems.
  • Containers are based on Images.
  • An Image is a file made up of multiple layers of instructions.

I came up with a poor programming analogy to help myself understand this. An Image is a Class, and the container is the instantiated object.

Docker can be run on both Linux and Windows hosts and there are now both Linux containers and windows containers.

There are quite a few benefits to using them, I’ll only mention a few to keep the read short:

  • Acts as a sandbox environment. You could spin up a Debian container play around in it and if you broke anything you could just throw it away and spin up a new one in seconds.
  • Aids in rapid and continuous deployment
  • Makes CI quite easy and efficient
  • Ensures your apps and resources are isolated and segregated
  • Portability

The main benefit for me is how it allows us to package up an application with all of the parts it needs, such as libraries, dependencies, and ship it as one package, and we know that it will work on whatever machine it is being run on.

Photo by Fancycrave 

Set up Docker desktop for windows

Docker desktop is a pretty neat tool that allows you to spin up docker containers on your windows machine. For those of you would don’t know what Docker is I have written an article about it called what-is-docker .

  • To get started download and install the file from the official DockerHub site.
  • When asked to pick windows or linux containers, choose linux. This can be changed later.
  • After the install ensure virtualisation has been enabled. You can check this in the Performance tab of task manager. If this is not enabled you will need to enable it via the BIOS settings.
  • You will also need to have Hyper-V enabled in the Windows Features directory. (Type Windows Features in the windows search bar)
  • Reboot your machine.
  • Check docker engine is running in the icon tool tray. If it is red then you have a problem.

Execute the following to check if it is working correctly:

  • docker --version
  • docker ps (there should be no containers at first, but this command should NOT fail)
  • Last step is to share the drives you want to be available to your containers. This can be done in the Settings menu under Shared Drives

From my personal experience I have found the tool to behave ‘unexpectedly’ at times. Whenever I changed my laptop’s password, the icon in the tool-tray would turn red. Overall though it really does make deploying web apps in containers quite interesting.

Definitely worth having a play around.

Photo by Rye Jessen

Basic Docker Commands cheat sheet

If you don’t know what Docker is check out this article what-is-docker

I have compiled a small list of the basic commands I find myself using mostly.

  • docker run – Runs a command in a new container.
  • docker start – Starts one or more stopped containers
  • docker stop – Stops one or more running containers
  • docker build – Builds an image form a Docker file
  • docker pull – Pulls an image or a repository from a registry
  • docker push – Pushes an image or a repository to a registry
  • docker export – Exports a container’s filesystem as a tar archive
  • docker exec – Runs a command in a run-time container
  • docker search – Searches the Docker Hub for images
  • docker attach – Attaches to a running container
  • docker ps – Shows all running containers
  • docker images – Shows a list of a ll images

Some additional useful commands:

  • docker exec -it <container name> bash – Steps into the command line of that container (this assumes bash is available in that container)
  • docker rm <container name> – remove a container
  • docker rm -v <container name> – remove a container and its volume
  • docker rmi <Imagename> <Imagename> – remove an image

Photo by Hannah Joshua