Understanding Docker Basic Fundamentals
Docker is basically divided into 2 types of editions; which are Community Edition (Free of charge) and Enterprise Edition (Paid version). So in this tutorial let’s see how to install docker in your computer and what are basic fundamentals included in docker.
First of all, let’s check out what’s the concept behind docker?
The basic purpose of docker is like this scenario. Its primary focus is to automate the deployment of applications inside software containers and the automation of operating system level virtualization on Linux. It’s lightweight and boots-up in seconds.
As it is mentioned in the above scenario, I’ll write something about “containers”.
What is a Container?
Basically, a container is the process which will be executed by the docker. Containers are basically two types; which are Linux container (Default one) and Windows containers.
Docker is running in server-client mode on Mac machines. And Docker supports natively on Mac machines. As a matter of fact, docker runs on Linux kernel. But, in the Windows operating system don’t have a Linux kernel like already installed.
Hence, in the early days; when installing docker into our windows operating systems we need to download the toolbox that was on docker web site. But, nowadays we do not need to follow that process. Because Docker company has now introduced “Docker for Windows” for Microsoft Windows.
So, what I meant above is that docker native part. It actually depends on the cloud-native term. In fact, cloud-native means how applications are created and deployed not where; it implies that the applications live in the public cloud as opposed to an on-premises datacentre.
Let’s start to move onto the installation process; below there.
But, before downloading docker, you need to create an account from DockerHub. So, after you create an account you have a docker id; save that one in your private notepad. Because you need that id during your installation process.
Okay, let’s move to the installation process; there are two types of installations.
- Docker -Windows installation.
- Docker -Mac Os installation.
First of all, move to Windows installation; before your installation, you should know about this,
Docker -Windows installation
What you know before you install
- Windows 10 64bit: Pro, Enterprise or Education (1607 Anniversary Update, Build 14393 or later).
- Virtualization is enabled in BIOS. Typically, virtualization is enabled by default. This is different from having Hyper-V enabled. For more detail see Virtualization must be enabled in Troubleshooting.
- CPU SLAT-capable feature.
- At least 4GB of RAM.
Note: If your system does not meet the requirements to run Docker Desktop for Windows, you can install Docker Toolbox, which uses Oracle Virtual Box instead of Hyper-V.
Let’s start Docker for Windows installation
- Download “Docker Desktop Installer.exe” file from download.docker.com URL.
- Double-click Docker Desktop for Windows Installer.exe to run the installer.
- Follow the install wizard to accept the license, authorize the installer, and proceed with the install.
You are asked to authorize
Docker.appwith your system password during the install process. Privileged access is needed to install networking components, links to the Docker apps, and manage the Hyper-V VMs.
4. Click Finish on the setup complete dialog to launch Docker.
After the installation part, we can move to start Docker for Windows application. To start it, search for Docker, select Docker Desktop for Windows in the search results, and click it (or hit Enter).
When the whale in the status bar stays steady, Docker is up-and-running, and accessible from any terminal window.
The related image is given below.
Now you need to login to the docker hub with your Docker ID & Password. That’s why I previously wrote in the above section to save your Docker ID and Password in your private notepad.
Now your Docker for Windows installation completed. Let’s move onto the Docker — Mac Os installation.
Docker -Mac Os installation
What you know before you install
- Docker mac os installation will be a little bit easier rather than windows installation. But, before that, you need have below conditions.
- Relationship to Docker Machine: Installing Docker Desktop for Mac does not affect machines you created with Docker Machine. You have the option to copy containers and images from your local
defaultmachine (if one exists) to the new Docker Desktop for Mac HyperKit VM. When you are running Docker Desktop for Mac, you do not need Docker Machine nodes running at all locally (or anywhere else). With Docker Desktop for Mac, you have a new, native virtualization system running (HyperKit) which takes the place of the VirtualBox system. To learn more, see Docker Desktop for Mac vs. Docker Toolbox.
- System Requirements: Docker Desktop for Mac launches only if all of these requirements are met.
- Mac hardware must be a 2010 or newer model, with Intel’s hardware support for memory management unit (MMU) virtualization, including Extended Page Tables (EPT) and Unrestricted Mode. You can check to see if your machine has this support by running the following command in a terminal:
- macOS Sierra 10.12 and newer macOS releases are supported. We recommend upgrading to the latest version of macOS.
- At least 4GB of RAM
- VirtualBox prior to version 4.3.30 must NOT be installed (it is incompatible with Docker Desktop for Mac). If you have a newer version of VirtualBox installed, it’s fine.
Note: If your system does not satisfy these requirements, you can install Docker Toolbox, which uses Oracle VirtualBox instead of HyperKit.
Let’s start Docker for Mac installation
- Download “Docker.dmg” file from https://hub.docker.com/editions/community/docker-ce-desktop-mac URL.
Docker.dmgto open the installer, then drag Moby the whale to the Applications folder.
Docker.app in the Applications folder to start Docker. (In the example below, the Applications folder is in “grid” view mode.)
4. You are prompted to authorize
Docker.app with your system password after you launch it. Privileged access is needed to install networking components and links to the Docker apps.
5. The whale in the top status bar indicates that Docker is running, and accessible from a terminal.
If you just installed the app, you also get a success message with suggested next steps and a link to this documentation. Click the whale in the status bar to dismiss this popup.
6. Click the whale to get Preferences and other options.
7. Select About Docker to verify that you have the latest version.
What is a Docker Image?
Concept of Docker Images
- In Docker, everything is based on images. An image is a combination of a file system and parameters.
- Images contain the binaries and dependencies.
- Image contains the data required to run the image.
- List Docker images (
- Images don't contain the OS and OS packages.
Docker Hub Repository
- Docker images can be downloaded from Docker Hub.
- Images can be committed with changes and have multiple versions; if you don’t provide a specific version number, the client defaults to latest.
Types of Docker images
Docker images differentiation
- Base Image: Images that have no parent image; usually images with an OS like Ubuntu.
- Child Images: Images that build on base images and add additional functionality.
- Official images: Images that are officially maintained and supported by the folks at Docker. These are typically one word long.
- User Images: Images created and shared by users like you and me. They build on base images and add additional functionality. Typically, these are formatted as user/image-name.
Download Docker-images (docker pull <image-name>)
Pull a specific version (docker pull <image-name>:<image-version>)
Docker Images Layers
Each image consists of a series of layers. Docker makes use of union file systems to combine these layers into a single image. Union file systems allow files and directories of separate file systems, known as branches.
Show image layers: docker history <image-name>
History command shows different layers, a command used for each layer, and the exact size of each image.
Upload Docker to Cloud
To access this feature user must have the account on hub.docker.com. So, docker cloud uses docker hub as it’s a native registry for storing both public and private repositories. Once you to push your images to Docker Hub, they are available in Docker Cloud.
The command to login: docker login
Here’s the command for pushing images to DockerHub: docker image push USER/<image-name>
Alright, let’s start to build a new docker image of your own…
Build Docker Images
In this scenario, I would like to present you in point form; I suppose you guys can understand easily in using point form. Dockerfile instructions are used to create the Docker Image. Let’s start all of the steps based on Docker file.
- FROM: The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions.
- A valid Dockerfile must start with FROM instruction.
- The base image can be any valid image.
- “FROM” is the very important instruction in a Dockerfile.
- An instruction format is like this: FROM <image>[:<tag>]
- LABEL: LABEL added to an image to organize images by project, record licensing information. For each LABEL, add a line beginning with the LABEL and with one or more key-value pairs. Actually which is a meta-data of docker image.
- LABEL instruction looks like this; com.example.version= “0.0.1-beta” or vendor1= “ABCD Incorporated”
- RUN: RUN instruction will execute any commands in a new layer on top of the current image and commit the results.
- The resulting committed image will be used for the next step in the Dockerfile.
- RUN instruction looks like this;
RUN apt-get update
RUN apt-get install -y curl
- CMD: CMD instruction should be used to run the software contained by your image, with any argument.
- There can only be one CMD instruction in a Dockerfile. If you list more than one CMD; then only the last CMD will take effect. The main purpose of a CMD is to provide defaults for an executing container.
- CMD instruction looks like this; CMD [“executable”, “param1”, “param2”]
- ADD: ADD instruction copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the image at the path <dest>(Destination).
- ADD instruction looks like this; ADD home/mydir/ (add all the files starting with “home”).
- VOLUME: VOLUME instruction should be used to expose any database storage area, configuration storage, or files/folders created by your docker container.
- WORKDIR: WORKDIR instruction sets the working directory for any RUN, CMD, ADD instructions that follow it in the Dockerfile.
Alright guys, let’s start to Build a Dockerfile. But, before that let’s see a sample Dockerfile using the above instructions.
RUN apt-get update
RUN apt-get install –y nginx
Build a Dockerfile
Docker image is built from Dockerfile. So, it really needs to be given a command. Command syntax looks like this, I will explain one by one after the command line;
docker build -t ImageName:TagName dir
docker build -t ImageName .
- -t: In this part mention a tag to the image.
- ImageName: This is the name you want to give to your image.
- TagName: This is the tag you want to give to your image.
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.
If you have any issues in this tutorial you can comment it. Feedback and criticism are more than welcome.