Docker, My Simple Tutorial

Install Docker Engine on Fedora Linux is simple just type :
$ dnf install docker
Download Images from Canonical it's small size, just "50MB" :
https://partner-images.canonical.com/core/xenial/current/
or From Fedora :
https://getfedora.org/en/cloud/download/docker.html
Import the Ububtu Image to Docker :
$ cat ubuntu-xenial-core-cloudimg-amd64-root.tar.gz | docker import - ubuntu/16.04
Import the Fedora Image to Docker :
docker load -i Fedora-Docker-Base-24-1.2.x86_64.tar.xz
Check Docker Images:
$ docker images
Run Impoerted Image with Specifice name :
$ docker run --name=server0 -it ubuntu/16.04 /bin/bash
Add what you want to the container with "apt-get" and type exit.
Check the container :

$ docker ps -a
Now we must Save the changes to Image :
$ docker commit -m "Added Apache2,PHP" -a "MiBellil" server0 ubuntu/16.04:v2
(((or)))
$ docker commit server0 ubuntu/16.04:v2
Check Docker Images :
$ docker images
To run/attach/stop the Container type :
$ docker start server0
$ docker attach server0
$ docker stop server0
Read Log Data in the Container :
$ docker logs server0
Run the Image in Background :
$ docker run -itd ubuntu/16.04 /bin/bash
One liner to stop / remove all of Docker containers:
$ docker stop $(docker ps -a -q)
$ docker rm $(docker ps -a -q)
The container can use as much memory as it needs. The memory reservation setting ensures the container doesn’t consume too much memory for long time, because every memory reclaim shrinks the container’s consumption to the reservation.

By default, kernel kills processes in a container if an out-of-memory (OOM) error occurs. To change this behaviour, use the --oom-kill-disable option. Only disable the OOM killer on containers where you have also set the -m/--memory option. If the -m flag is not set, this can result in the host running out of memory and require killing the host’s system processes to free memory.
The following example limits the memory to 100M and disables the OOM killer for this container:
$ docker run -it -m 100M --oom-kill-disable ubuntu:14.04 /bin/bash
The following example, illustrates a dangerous way to use the flag:
$ docker run -it --oom-kill-disable ubuntu:14.04 /bin/bash
The container has unlimited memory which can cause the host to run out memory and require killing system processes to free memory.

Difference between save and export
A Docker image can be saved to a tarball and loaded back again. This will preserve the history of the image.
# save the image to a tarball
docker save <IMAGE NAME> > /home/save.tar
# load it back
docker load < /home/save.tar

A Docker container can be exported to a tarball and imported back again. This willnot preserve the history of the container.
# export the container to a tarball
docker export <CONTAINER ID> > /home/export.tar
# import it back
cat /home/export.tar | docker import - some-name:latest

Comments

Popular Posts