Skip to content

What is docker?

Docker is a containerization platform that packages your app and all its dependencies together in the form called a docker container to ensure that your application works seamlessly in any environment.

There are multiple applications running on the same machine. These applications are put into docker containers and any changes made on these containers does not affect the other container. Each container has different Os running on the same physical machine. Docker helps you to create, deploy and run applications using containers.


Full size image

Containers are a form of a packaged up software application that essentially isolates a program from other environments. By placing a program in a container, it becomes independent and therefore easier to update and scale. The container includes not only the program itself, but also all the essential elements that the program needs to run. The benefits of this include an increase in portability and also a reduction in deployment time because containers are lightweight and relatively fast.

Containerization is increasingly popular because containers are:

  • Flexible: Even the most complex applications can be containerized.
  • Lightweight: Containers leverage and share the host kernel.
  • Interchangeable: You can deploy updates and upgrades on-the-fly.
  • Portable: You can build locally, deploy to the cloud, and run anywhere.
  • Scalable: You can increase and automatically distribute container replicas.
  • Stackable: You can stack services vertically and on-the-fly.

Info

A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

Images and containers

A container is launched by running an image. An image is an executable package that includes everything needed to run an application--the code, a runtime, libraries, environment variables, and configuration files.

A container is a runtime instance of an image--what the image becomes in memory when executed (that is, an image with state, or a user process). You can see a list of your running containers with the command, docker ps, just as you would in Linux.

Containers and virtual machines

A container runs natively on Linux and shares the kernel of the host machine with other containers. It runs a discrete process, taking no more memory than any other executable, making it lightweight.

By contrast, a virtual machine (VM) runs a full-blown “guest” operating system with virtual access to host resources through a hypervisor. In general, VMs provide an environment with more resources than most applications need.

Container solution Virtual machine solution
Full size image Full size image

It may look like a virtual machine at first but the functionality is not the same.

Unlike Docker, a virtual machine will include a complete operating system. It will work independently and act like a computer.

Docker will only share the resources of the host machine in order to run its environments.

Where and how to persist application data

  • Avoid storing application data in your container’s writable layer using storage drivers. This increases the size of your container and is less efficient from an I/O perspective than using volumes or bind mounts.
  • Instead, store data using volumes.
  • One case where it is appropriate to use bind mounts is during development, when you may want to mount your source directory or a binary you just built into your container. For production, use a volume instead, mounting it into the same location as you mounted a bind mount during development.

How to install docker?

Best place for the latest install instructions is the docker documentation.

However here is the short version for Ubuntu:

  1. First, just update the apt package index:

    sudo apt-get update
    

  2. Then Install packages to allow apt to use a repository over HTTPS:

    sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
    

  3. Add Docker’s official GPG key:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    

  4. Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint. And I also got the same fingerprint.

    sudo apt-key fingerprint 0EBFCD88
    

  5. Add the stable repository:

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    

  6. Update the apt package index again according to official site.

    sudo apt-get update
    

  7. Install the latest version of Docker CE

    sudo apt-get install docker-ce
    

  8. We can check the version of the Docker:

    sudo docker -v
    

  9. We can also run the hello world to see whether it is installed successfully:

    sudo docker run hello-world
    

Docker Actually Isn’t Difficult to Use — And It’s Worth It

Think about a common local development tool like Vagrant. Vagrant mimics your production server, but you may end up with version, supporting technology or network differences. When you put your application in a container, the virtual machine the container’s running on becomes irrelevant, and the container itself is your build artifact.

When you have your application in a Docker container, you can be sure that the code you’re testing locally is exactly the same build artifact that goes into production. There are no changes in application runtime environments. That makes Docker an exceptional tool all the way from development through production.

And, fortunately, Docker isn’t too hard to learn. It’s easy to play with, and the learning curve is relatively small.

So why might it seem hard to use? Probably because you haven’t had the chance to try it yet.

Source

Docker registry

Registry is a place to store all the images. When docker is installed , a local registry is created to store all the images.

Try docker images command to list all the images currently in your local registry.

Docker Hub is a public repository that has over 100,000 images. Always check the hub to see if there is pre-built image that might serve your needs before building your own image.

We can move the images between local and remote registries using docker push and docker pull commands. The default remote registry is Docker Hub unless specified otherwise.

Private registry

A private registry is used as your private repository for Docker images. We can use it just like other public repositories available: Docker Hub, AWS ECR (EC2 Container Registry) etc.

Often organisations have their own private registry to assist collaboration and accelerate development.

We need a private repository if we want to keep our Docker images private and don’t want to push it to public repositories. We can use a private repository to shift our Docker images from one stage to another just like form Development to QA and further ahead to Stage and Production.

The docker documentation has a detailed tutorial how to set up a private registry by yourself: https://docs.docker.com/registry/deploying/


Further reading