Understanding Dockers and Containers in depth

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. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that the machine might have that could differ from the machine used for writing and testing the code.

1. Run Docker: Install docker desktop(macOS, Linux and Windows)
Docker desktop has various other tools, Docker Engine is a tiny little component of the entire suite of tools. The main tools are Engine, CLI, Compose, BuildKit, Kubernetes and etc.

Note: Docker Desktop is not for servers. Use the docker engine instead.

2. Three Major ways to run Containers

  • Locally(Docker Desktop, RD)

3. Installing Links
Mac
Windows
Linux
Linux Server

4. Frequently used commands

docker version #check version of client and serverdocker info #gives out most config values of engine

5. Image vs Containers

  • An Image is an application that we want to run

6. Let's start a new Container
Using the command below we will initiate our container

docker container run --publish 80:80 detach nginxordocker container run -p 80:80 -d nginx____________________________________________________________________
-d is the short version of --detach. By running in detached mode, we are able to have access to our command line when the container spins up and runs. Without it, we would have logs constantly fed onto the screen.

Now if I go to my browser and search localhost

The container is running

7. List Container
Use the command below to list the running containers

docker container ls -a
the output of the container ls command

8. To create a container with a custom name
use the command below

docker container run publish 80:80 --detach --name webhost nginx********************************************************************detach = this lets the process run in the background
********************************************************************

9. Delete Containers
use the command below:

docker container rm -f [“container id” or “first three chars of container id”]
deleting a container

10 . List running processes in specific Container
To list use the command 👇🏻

docker top [container name]ps aux #shows all running processes

11. VM-Ware -vs- Dockers
True, there are some similarities, but there’s so many things that just aren’t the same.

VM -vs- Docker

Lets see the real time scenario which best describes the difference.

Source : Quora

12. Lets start up a Mongo DB
We’re going to call it mongo. We’re going to run it in the background and we’re using the Mongo image.Use the command👇🏻

docker run --name mongo -d mongo 

13. To restart a Stopped container
Use the command👇🏻

docker start mongo

14. Manage Multiple Containers
We’re going to start up a three-container application. We’re not actually going to set up these three different containers with application data or our source files.

1. run a nginx, a mysql and a httpd(apache) server2. Run all of them --detach or -d and, name then with --name3. nginx should listen on 80:80, httpd on 8080:80, and mysql on 3306:3306

one of the options for the container run command is an environment variable passing. So, -e or — env will pass any environment variable you want to pass into that container. This is a very common way for us to pass environment based settings into our containers. It’s quite often to have different environment variables for test or dev, versus production and the with the stop and the rm commands.

4. when running mysql, use the --env option or -e to pass in MYSQL_RANDOM_ROOT_PASSWORD=yes5. Use "docker container logs db" on mysql to find the random password it created on startup6. clean it up all with docker container stop or docker container rm(both accepts multiple names or ids)7. use docker container ls to ensure everything is removed 

14. Whats going on inside the running Containers?
To understand this better, Lets run 2 containers to understand this better using the commands below.

docker container run -d --name nginx nginx #run nginx docker container run -d --name mariadb -e MARIADB_RANDOM_ROOT_PASSWORD=true mariadb    #creates mariadb 

Note : Arm support for MySQL
the official MySQL image only supports Intel/AMD processors.MySQL has multiple variants, though, that we can use for other processors (spin-off projects that are MySQL compatible).MariaDB is a great alternative and even supports MySQL-specific environment variables.
So, if you’re using Apple Silicon (M1, etc.) or a Raspberry Pi, which are both arm64 based processors, just change mysql to mariadb and everything should work in this course!

Please review the screenshot below to see the actual working

2 containers are created

Get the metadata about the container
The following command shows the metadata about the container such as startup configs, volumes, networking etc.

docker container inspect mariadb

Show live performance data for all containers
This is great way of monitoring the performance locally, use the command below to see the live performance data👇🏻

docker container stats.    # performance stat for all containers
output of docker container stats : shows live performance data

Get list of processes under one container : use command 👇🏻

docker container top       # process list in one container

Lets delete after we are done

This article is in the development phase as I am learning through it.

*******************************************************************
Disclaimer:

This article is basically my notes as I am learning Dockers right now. I hereby declare that I have used various sources as reference to the content of this article listed below.

References : Udemy, Quora

Manminder Singh

*******************************************************************

--

--

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
Manminder Singh

DevOps Engineer| 3x AWS Certified | Terraform Associate Certified | Linux Certified | Former IT HR | Naval Brat