Everything on Docker! (Part l)

  1. Linux: https://docs.docker.com/engine/install/ubuntu/
  2. Windows: https://docs.docker.com/desktop/windows/wsl/
  3. macOS: https://docs.docker.com/desktop/mac/install/

What is an Image?

Docker images!

What is a container?

Docker containers!

What is going to happen if you run this command?

  • Execute: docker run hello-world
  • Docker client (CLI): receives that command and takes some actions based on it.
  • Docker Server: CLI communicates with the docker server to see if there is an image called “hello-world”! It is called image cache! If there is no image that exists, then the docker server will communicate with the docker hub where some pre-exist images reside.
  • Docker Hub: Docker hub receives the request from the docker server to download the image file which will be allowed! Therefore, the image will be downloaded from the docker hub to the docker server!
  • Docker server now will find the image in the “Image Cache” section. Then a container will be created, which is the instance of the “hello-world” image. That being said, the instance will run the simple program called hello-world in the container. You will be able to see something like this:
Your first docker application!

How to delete/remove all docker containers?

How to get the logs of a container?

How to execute an additional commands in a container?

Some commands and their applications:

  • docker ps — only shows the active containers
  • docker ps -a — shows all the container (active/inactive)
  • docker images — shows all the images that your system currently has!
  • docker stop <container-id> — stops the specific container
  • docker rm <container-id> — delete the specific container
  • docker rmi <image-name> — delete the specific image

How to get a command prompt in a container?

Prompt in a container!

How to run an image (that creates a container) with a prompt?

Allowing prompt while running an image!

How to create your custom image?

  • Dockerfile: It’s the main file where all the instructions reside. Every dockerfile follows the same structure. Step 1: Specify the base image. Step 2: All the dependencies and requirements to run the program as intended. Step 3: Specify a command to run on a container startup.
  • Docker Client: After creating the Dockerfile, you will try to build the image right? Dockerfile will be received by the docker client.
  • Docker Server: Docker client will forward all the instructions to the docker server. The docker server does the heavy work, which means it will execute every command inside the dockerfile and create an image. Then you will run the image, that will create a container (an instance of the image) to implement all the mentioned applications.
  • Create a Dockerfile
  • Build the image: “docker build .”
  • Run the image: “docker run <image-id>”
Dockerfile to install redis-server!
  • What is the base image? : No container has an operating system. If you want to create a container, then it needs a starting point or a base image where it can start. Later on, you can modify what to do! By using this base image, Redis can be installed.
  • Why alpine? : Alpine is like a Windows, macOS where it supports some program to install whatever you need. Alpine provides and acts exactly this way that is able to install Redis. You use FROM to load the base image.
  • Install dependencies? : You can see RUN, which will execute the following command. APK stands for Alpine Linux package manager. You use the apk command to delete, install, upgrade, or list software on a running Alpine Linux-based system. Does that answer the question of “What is the base image?” and “Why Alpine?”. It should, right?
  • CMD? : CMD instruction allows you to set a default command, which will be executed only when you run a container without specifying a command. The above example will start the Redis-server. Cool, right?
It’s running!
  • docker build -t <customized name>/<repo/project name>:version . : It will tag the image to a customized name!

Create a project and dockerize it!

package.json
Index.js
Dockerfile
Image build in a container!
Application works!
uh oh!
Port Mapping!

The Result!?

Worked!!
  • Wrong base image selection.
  • Not copying the files from the host machine to the container location.
  • Port mapping.
ssh terminal in the container!
ssh terminal in the container!
Minimizing cache and rebuilds!

--

--

--

Python Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Decode AIS message in your browser

Simple Event System for Unity 3d

Women Who Code Delhi Mentorship Program 4.0-Week 1

Hiring Virus for Testing !

Minecraft server on Digitalocean, with VPN

Continuous Deployment to Kubernetes (EKS) using AWS CodePipeline, AWS CodeCommit and AWS CodeBuild

Current Progress, the next Application!

In Software Engineering, Knowledge Is Only The Beginning

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mahedi Hasan Jisan

Mahedi Hasan Jisan

Python Developer

More from Medium

ElasticSearch Python

DATABASE IN PYTHON

Page Object Model (POM) in Selenium Python

Optimize Docker Size Image with Python Environment