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.
Docker Registry and Repository
Docker registry is a service which is hosted by third parties, such as:
- Docker hub: hub.docker.com
- AWS container registry: aws.amazon.com/ecr
- 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
- The first step is to go to this link and select Get Docker Desktop — Windows (stable):
docker-ce-desktop-windows
- 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.
- 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.
- Now if you have a Docker id you can log in, otherwise go to the next step.
- 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.
- 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
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
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
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
Then go to the path of the project:
> docker login docker.io
> dockerpush reponame/imgname:latest
Then check your repository page in Docker to make sure if all is ok.
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.
History
- 20th July, 2019: Initial version