Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / containers / docker

Dockerize

5.00/5 (6 votes)
20 Jul 2019CPOL3 min read 13.1K  
This article is a brief, succinct and practical exploration in Dockerizing.

Introduction

Docker is a software platform for application packaging in a convenient way. Docker creates a lightweight, reusable, portable and executable package of software for development, shipment, and deployment. Developers combine multiple and different software (platforms) together in order to customize and create a specific application. For example, there are many requirements and expertise to set configuration for using Kafka facilities in big data.

Image 1

Docker Registry and Repository

Docker registry is a service which is hosted by third parties, such as:

  1. Docker hub: hub.docker.com
  2. AWS container registry: aws.amazon.com/ecr
  3. Google container registry: cloud.google.com/container-registry

Developers put their images in one of the mentioned Docker registries. On the other hand, a Docker Repository is a set of various Docker images with the same name but different versions or tags.

Docker Composer

Docker CLI is specific for the single or individual container, such as:

docker run hello-world
docker pull repository/image_name

Those mentioned CLI instructions have access to daemon API. While Docker composes CLI can combine multi-container with running one command line docker-compose up.

It is easy to keep tracking, networking and resource management and last but not least it is reusable. Images are designed to be orchestrated of layers of the related images. It needs Docker file in YML which allows multiple containers.

YAML (Yet Another Markup Language or Ain’t Markup Language) is a markup language which is more data-oriented rather than traditional markup-oriented (such as XML or HTML). It is case sensitive and human readable which is mostly used in configuration among different platforms.

Docker composes just needs to be written in one docker-composer.yml and run it by docker-compose up. Therefore, it is possible to get a service or application from Docker by one command line.

Docker Image and Container

Building Docker file is the first step to make an image and when client pulls the image and starts to run the image, it becomes a container, in better words container, is an instance of the image, such as an object which is an instance of a class in object-oriented.

Install Docker on Windows

  1. The first step is to go to this link and select Get Docker Desktop — Windows (stable):

    docker-ce-desktop-windows

    Image 2

  2. Click on Docker for Windows Installer which is a .exe file and try to install Docker as follows: You can select the second checkbox because when you are working in Windows, it is possible to use the container for both Windows or Linux, but pay attention to the tag of image Docker because if it is specified for Linux so the container should be Linux too.

    Image 3

    Image 4

    Image 5

    Image 6

  3. Enable Hyper-V for windows, after that your machine will be installed and the rest of other VirtualBox is not able to work parallelly with Docker.

    Image 7

  4. Now if you have a Docker id you can log in, otherwise go to the next step.

    Image 8

  5. In order to make a Docker id, select sign up and enter Docker id which should be unique. Then you should verify your email address.

    Image 9

    Image 10

    Image 11

    Image 12

  6. To check whether Docker has been installed correctly, please enter each of the below lines and after end press the Enter button, such as the picture. (You can use “Windows PowerShell” for running Docker commands.)
     docker — version
     docker-compose –version
     docker run hello-world

    Image 13

    Image 14

Install Docker on Linux

Install Docker Repository:

There are two ways to install Docker on Linux:

Install Docker from Repository:

sudo apt-get update
sudo apt-get install
apt-transport-https
ca-certificates
curl
gnupg-agent
software-properties-common
curl -fsSL <a href="https://download.docker.com/linux/ubuntu/gpg">https://download.docker.com/linux/ubuntu/gpg</a> | 
     sudo apt-key add — Verify fingerprint by entering last 8 character:
sudo apt-key fingerprint
sudo add-apt-repository
"deb [arch=amd64] <a href="https://download.docker.com/linux/ubuntu">https://download.docker.com/linux/ubuntu</a> \ $(lsb_release -cs) \ stable"

To install Docker CE on Linux, go to this link, Ubuntu must be 64 bit for Docker:

docker-ce — ubuntu

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo docker — version
docker-compose — version
sudo docker run hello-world

Image 15

Image 16

Image 17

Create Composer File, docker-composer.yml

In this example, Kafka needs Zookeeper to run. So, there is a need to pull two different images from docker and combine them with each other, therefore according to the first chapter “Docker Composer”, instead of pulling images one by one, we must write “docker-compose.yml”, and change directory to where is located docker-compose.yml and then run:

 docker-compose up

Image 18
Image 19

Image 20

Image 21

Configuration

version: "2"
services:
  kafkadocker:
    image: "spotify/kafka:latest"
    container_name: kafka
    hostname: kafkadocker
    networks:
      - kafkanet
    ports:
      - 2181:2181
      - 9092:9092
    environment:
      ADVERTISED_HOST: kafkadocker
      ADVERTISED_PORT: 9092
  kafka_manager:
    image: "mzagar/kafka-manager-docker:1.3.3.4"
    container_name: kafkamanager
    networks:
      - kafkanet
    ports:
      - 9000:9000
    links:
      - kafkadocker
    environment:
      ZK_HOSTS: "kafkadocker:2181"
networks:
  kafkanet:
    driver: bridge

Push Docker Images to Docker Repository

Image 22

Image 23

Then go to the path of the project:

> docker login docker.io
> dockerpush reponame/imgname:latest

Image 24

Then check your repository page in Docker to make sure if all is ok.

Image 25

Pull What You Have Pushed Now for a Test

Create a YML file with the service and container name and specified image that you want to pull it. Change directory to YML path and run docker-compose up.

Image 26

Image 27

Image 28

Image 29

History

  • 20th July, 2019: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)