Hello Docker 😄 —Part I

Search for a command to run...

No comments yet. Be the first to comment.
Scaling containers on Kubernetes with Replicatsets or scale services with docker swarm is a very easy task! but what about scaling containers in a non managed environment, when you have high traffic, absolutely you need to scale and load balance the ...

I was working with Kubernetes and I just want to check my pods in the current workspace, in a funny way 😅, I will use bash for just one reason, it's the Linux native languages no need for other languages and libraries Actually, I was inspired by a...

In this post we will deploy a simple dockerized Machine learning application written with the Flask micro-framework to the Heroku (PaaS), using one of the leading CI/CD tools, which is Gitlab!, all used tools are free and no fees in achieving this tu...

Building binaries on compiled languages like Rust and Go as Static or dynamic linking makes a huge step on code security, I mean no one can access your code, reading it !, but in many use cases they can by doing some complicated reverse engineering m...

Setting up a full-featured mail server is an actual PAIN for a system admin, you have to interconnect many software pieces and a lot of testing especially security and spam if you plan to use it for your company ... In this Post, I will take you in m...

In this story i will share my docker experience, so, be ready ! to know the most used container technologies in the hole world ! . I will help you to get started in docker also we will deep dive into cool features … , and by the end of this story you will be able to make your own projects using docker and docker-compose 😅. The second part is ready : hello docker part II
In a simple way … Docker is a way to bundle an app and it’s requirements into a single Image that can be runnable in any environment like Windows, Linux, Mac os and of course the cloud.
A docker Image is a micro os like ubuntu, debian and archlinux …, But what is a micro os ? simply it’s a very tiny os that contains only a file system and some basic command and of course a package manager like apt and pacman …
I am not going through the installation process or explaining the functional part of docker … i will go through examples from real life and some cool tips and tricks .
You must READ them 😠
Check your docker status by running this command :
$ sudo systemctl status docker
If docker is not running make sure to run this command
$ sudo systemctl start docker
After installing docker, now you are able to follow this article, so … let’s run our first container by running this command and i will explain every step 😃
$ docker run hello-world
This is the output :

By this command we tell the docker engine to run an image called “hello-world”, which is an image that contains a simple script with the output that begins with “ Hello from docker …” so … what happens here ?
The docker engine searches for this image in the local registry but he tells us that he didn’t find it so it goes to a global registry which is a huge and public place for free images (created by other peoples ) called docker hub.
He pull or download the image then he run it, and finally we get the message or the execution result of the script inside the image. To download only the image we use ’’docker pull hello-world’’.
Let’s try another one , in this case i have an ARCHLINUX based os and i want to run an alpine system with docker and make some work on it so let’s go 😄
docker pull alpine:latest
docker run -it alpine sh
Output :

We have downloaded the alpine image and we run it interactively by adding “ -it” and “sh” at the end :
-t option ( we can give input and type some commands to interact with the alpine system)The other commands ( ls , cat …) are a basic commands that are founded on any other Linux systems.
What is the difference between a docker image and a container ? Simply the docker image is the basic resource and it can be shared by multiple containers but how ? when we make a “docker run” , the docker engine make a snapshot or a copy of the base image in the memory and we use it like we did with alpine ,after some work on the snapshot or the container we usually stop and exit the container, and every container is identified with a unique hash (ID),
To add the changes that we make on the snapshot to the base image we use the “commit” command to persist our changes so let’s try out :
Watch this demo :

docker commit
We have created a new image named “_alpinemodified” that contains a “hello.sh” fileunder the “/home” folder . You surely notice that the original modification in the alpine image is gone now.
Another way to save changes or create some stuff in containers is the “Dockerfile” , which is a a set of instructions that define the final state of your image .
This file uses YAML syntax which is easy to understand and so clean 😄, so let’s go writing our first Dockerfile :
dockerfile
In this file we have two keywords :
let’s build the image :
$ docker build -t hello .
note: don’t forget the dot “.” please !!
Watch the demo :

hello_alpine
To get all images try to run : docker images , if you want to get more information about your image run this command : docker inspect hello and try to figure out what happens here , i will cover this topic in the next stories … .
Finally, this tutorial is just an introduction to docker for beginners, in the next parts i will talk about more advanced features in docker. If you have feedback feel free to share them with me Hatem Ben Tayeb.
If this post was helpful click the clap button as much as possible 😃. The second part is ready : Learn Docker From Scratch