Blue Flower

What is a program? Job? Process?

Set of instruction written in a programming language,

1) stored in the persistent media is called "program" (ex: helloworld.cs)

2) same instruction inside the RAM (memory) during execution is called "job"

3) same instruction inside the processor during execution is called "process"

Note: You can see the "program" in persistent media the "process" details in the OS utility ("Task Manager" in windows)

What is docker?

Its a new way of running the "process" in an OS

What is the use of Docker?

It encapsulates all your application's dependencies (bin/libraries) into a container

Difference between Docker & VM?

> Virtual machine encapsulates Operating System(OS)

> Docker encapsulates your application

# In VM, you test your application in DEV, UAT & LIVE machines with separate environment setup on each machine

# In Docker, you put your application and all its dependencies into a single unit of file and test it and thus it always have same environment setup

$ In VM, guest OS run between host OS and virtualization layer (ex: Hypervisor in Windows)

$ In Docker, there is no more guest OS only the docker layer between OS and your app's bin/lib

How to install Docker freshly on machine?

It can be installed in 2 major ways

1. Setup docker repository on local host and install docker engine. In this case, its ease to upgrade docker engine by running command "sudo apt-get update".  Its the recommended way. For more details https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-using-the-repository

2. Directly download the package from https://download.docker.com/linux/ubuntu//dists

In this case, you need to check for newer version and manually install every time

For more detail: https://docs.docker.com/install/linux/docker-ce/ubuntu/

How to install NodeJS on a fresh Linux machine?

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install nodejs
curl is a command line utility to upload/download an application from remote
apt - newer version of apt-get  (advanced package tool)
sudo - superuser do (similar to run as "administrator" in windows)

 

How to restart the container when its image is changed?

You can use one of the docker monitor tool like watchtowser, Ouroboros etc., 

It will monitor running container and update them if any new changes in its image

When it update the container it reuses all the configuration (port, environment variable, ...) specified on launching the container for the first time

When can one go for "docker compose" ?

If there is a need to start multiple container as a single service ie., instead start each container seperately.

Example,
If you want to have a database setup in one container and your application in another container.  Now in order to start the application first you need start the database container followed by application container.  So its one of the best example candidate to go for docker compose.
 
Some useful docker utilities?
 
watchtower: to monitor docker container and update when its image is changed
 
$docker run -d --name watchtower --rm -v
/var/run/docker.sock:/var/run/docker.sock v2tech/watchtower --interval 30

above download the watchtower and monitor all running container and update it when their images updated

$docker run -p 9000:3002 --name myhelloworld cmraja/myhelloworld:latest

(assume that above "myhelloworld" uploaded in hub.docker.com under account "cmraja" in public. If its private you need to login before execute this command

For more detail: https://hub.docker.com/r/v2tec/watchtower/

docker system prune: remove unsed data (image, container, network, volume...)
 
$ docker system prune

WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y

Note: Before prune, "docker-gc" was used to collect the unused image but its deprecated

For more detail: https://docs.docker.com/engine/reference/commandline/system_prune/


docker-slim: its a pill to reduce your docker image fat ie., it will reduce your docker image size dramatically without any change

$docker-slim build --http-probe cmraja/myhelloworld

It has been used with Node.js, Python, Ruby, Java, Golang, Rust, Elixir and PHP (some app types) running on Ubuntu, Debian, CentOS, Alpine and even Distroless

For more detail: https://github.com/docker-slim/docker-slim


ctop: it provides metrics for specific or multiple containers more concisely

$ctop

Note: no arguments required

Fore more detail: https://github.com/bcicen/ctop

 

How to use docker commands without "sudo" ?


Step 1: add new group called "docker" if it doesn't already exist

           sudo groupadd docker

Step 2: add the connected user "$USER" to the docker group.

          sudo gpasswd -a $USER docker

Step 3: enforce the newly created group 

            newgrp docker

            (or) simply log out/in to activate the changes in groups

Step 4: now you can run all docker command without "sudo"

            docker run hello-world

You have no rights to post comments