כל המידע על מחשוב ענן במקום אחד

Docker getting started – part 1

Docker is a software that allow us to do operating system visualization.

It uses the Linux kernel to isolate process from their hot machine and other process. The docker itself is written with Go.

You can install docker on windows and Macintosh, but it in order to work on those system, it will install a linux VM. And all docker images are images of linux variants. The linux kernel of the container is the same as the host kernel (in the case of Windows and Macintosh the same for the linux vm and the container).

One of the main reason to use docker is that it solve the problem of “it works on my machine”, this is because the when you package your app inside the docker the environment is the same. Anther reason is that it solve dependency conflict. For example if one component of you app need version 3 pf python, and the other part need version 2.7 of python, then you just put them in different container, and for every container you put the correct version of python.

The biggest advantage of docker over VM is the small overhead in the start time of the docker and small footprint it has on memory and cpu consumption.

The memory consumption of docker container is almost the same has the memory consumption of the process that run inside it, unlike VM that duplicate the whole OS and has a far more memory and CPU consumption.

A different between docker and traditional VM, is what happen when the docker stop and restart, in docker all change disappear. You can however create volume or mount directory to the host, in these cases, changes that are made to the mounted directories and volumes are persistence.

So in essence docker image are immutable, every time you start it, all previous change (that have happened inside the container) disappear.

An important thing to know about docker container is that all process inside the container are running on the host machine are jailed, this is strongly different from traditional VM where you wont be able to see the process in host machine. In the case of docker, using ps to scan all processes in the host machine will show all the processes in the docker container as well.

So to summarize the points above:

Docker images are immutable, so if you stop and the run again container, all changes to the file system disappear, unless you are explicitly using volumes or mount directories to the host. So if you started docker container, deleted everything, stopped the container and then started it again, all changes would disappear, unless you used volume or mount directory to the host.

The linux kernel is shared between all containers and the host.

All the process inside docker containers are visible in the host and can be detected by using ps command. The processes are running in the host machine but they are jailed and see only the container file systems and the resources that docker show them.

‍

Installing docker is easy.

On Ubuntu:

sudo apt-get install docker.io

After you install docker you need to be root to work with docker.

If you want to work with docker with your user and not root then you need to add your user to the group docker

sudo usermod -aG docker < userName >

After you add your user to the docker group then you can work with docker without sudo command.

So the first thing you would like to do is to retrieve information about the docker server and the container, you do this by running:

docker info

This command will tell how many containers are running and their current state.

if you want to exist the container without stopping it or making it finish, then press CTL + p + q . Using this keys will take you out of the container to the host but wont finish the container.

If docker can not find the images local then it will try to fetch it from dockerhub, therefore the line Unable to find image 'ubuntu:latest' locally

Every container has as ID, in the example above the container id start with ebeecb1b874e.

We can use this id in order to reattach to the container or to mange them, but a better way is to give the container a semantic name.

Docker is a software that allow us to do operating system visualization.

It uses the Linux kernel to isolate process from their hot machine and other process. The docker itself is written with Go.

You can install docker on windows and Macintosh, but it in order to work on those system, it will install a linux VM. And all docker images are images of linux variants. The linux kernel of the container is the same as the host kernel (in the case of Windows and Macintosh the same for the linux vm and the container).

One of the main reason to use docker is that it solve the problem of “it works on my machine”, this is because the when you package your app inside the docker the environment is the same. Anther reason is that it solve dependency conflict. For example if one component of you app need version 3 pf python, and the other part need version 2.7 of python, then you just put them in different container, and for every container you put the correct version of python.

The biggest advantage of docker over VM is the small overhead in the start time of the docker and small footprint it has on memory and cpu consumption.

The memory consumption of docker container is almost the same has the memory consumption of the process that run inside it, unlike VM that duplicate the whole OS and has a far more memory and CPU consumption.

A different between docker and traditional VM, is what happen when the docker stop and restart, in docker all change disappear. You can however create volume or mount directory to the host, in these cases, changes that are made to the mounted directories and volumes are persistence.

So in essence docker image are immutable, every time you start it, all previous change (that have happened inside the container) disappear.

An important thing to know about docker container is that all process inside the container are running on the host machine are jailed, this is strongly different from traditional VM where you wont be able to see the process in host machine. In the case of docker, using ps to scan all processes in the host machine will show all the processes in the docker container as well.

So to summarize the points above:

Docker images are immutable, so if you stop and the run again container, all changes to the file system disappear, unless you are explicitly using volumes or mount directories to the host. So if you started docker container, deleted everything, stopped the container and then started it again, all changes would disappear, unless you used volume or mount directory to the host.

The linux kernel is shared between all containers and the host.

All the process inside docker containers are visible in the host and can be detected by using ps command. The processes are running in the host machine but they are jailed and see only the container file systems and the resources that docker show them.

‍

Installing docker is easy.

On Ubuntu:

sudo apt-get install docker.io

After you install docker you need to be root to work with docker.

If you want to work with docker with your user and not root then you need to add your user to the group docker

sudo usermod -aG docker < userName >

After you add your user to the docker group then you can work with docker without sudo command.

So the first thing you would like to do is to retrieve information about the docker server and the container, you do this by running:

docker info

This command will tell how many containers are running and their current state.