Docker – quick introduction. Part 1
Posted by danielDec 21
In these series of Docker tutorials, i will walk you through a hands on experimentation with Docker. The operating system I am working on is Ubuntu 16.04.
Docker is a containerization technology which allows deployment of applications in containers. Its advantage is speed, a docker container hosting an application would be up and running in a few milliseconds.
As opposed to Virtual machines, containers run on top of the host OS. They share the host kernel. Thus you can only run a Linux container on a Linux host or machine.
Docker Installation – use this link for instructions on how to install Docker.
Installation Limitation – Docker runs on 64-bit OS only and it supports Linux kernel version 3.10 and above. You can verify this using the commands below –
root@lindell:~# arch x86_64 root@lindell:~# uname -r 4.4.0-47-generic
Docker – terminology
-
Images – are the building blocks of Docker. Once created or built, they can be shared, updated and used to launch containers. No image, no containers.
Containers – are images in action. Containers give images life, containers are image plus all the ecosystem the Operating system need to run the application.
Registry – where images are stored. They can be public or private. DockerHub is a typical example of public registry.
Data volumes – persistent storage used by containers.
Dockerfile – file containing instructions to be read by Docker for building a Docker image.
Node – physical or virtual machine running Docker engine.
Our first Docker container
After installing docker and making sure that the Docker engine is running, run the commands below to check the Docker images(‘docker images’) available or if any Docker containers are running(‘docker ps’). Both commands should not return any results if this is a first time installation.
root@lindell:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE root@lindell:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
The next step is to get a Docker image from Docker Hub. For security reasons, we are going to use only official images –
root@lindell:~# docker search --filter=is-official=true ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 5238 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 69 [OK] ubuntu-debootstrap debootstrap --variant=minbase --components... 27 [OK] root@lindell:~# docker run -ti ubuntu /bin/bash Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu b3e1c725a85f: Pull complete 4daad8bdde31: Pull complete 63fe8c0068a8: Pull complete 4a70713c436f: Pull complete bd842a2105a8: Pull complete Digest: sha256:7a64bc9c8843b0a8c8b8a7e4715b7615e4e1b0d8ca3c7e7a76ec8250899c397a Status: Downloaded newer image for ubuntu:latest root@d1b13e2c3d3f:/# docker images bash: docker: command not found root@d1b13e2c3d3f:/# hostname -f d1b13e2c3d3f root@d1b13e2c3d3f:/# uname -r 4.4.0-47-generic
We just downloaded an official Ubuntu image and started an Ubuntu container by running /bin/bash inside the newly started container. The ‘-ti’ option runs bash interactively(-i) by allocating a pseudo-TTY(-t).
Note that – the kernel version on the container is the same as the host’s kernel version. During first run, Docker will try to find Ubuntu image in our local storage, if it can’t find it, it downloads it from Docker Hub. On next runs, starting the containers will be much faster.
If we check the images and processes running now –
root@lindell:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 104bec311bcd 5 days ago 129 MB root@lindell:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d1b13e2c3d3f ubuntu "/bin/bash" About a minute ago Up About a minute
At this point, if we exit from the container, docker ps will no longer show the container as it has been terminated. We use ‘docker ps -a’ instead to view it and then use ‘docker start’ command to start the container –
root@d1b13e2c3d3f:/# exit exit root@lindell:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES root@lindell:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d1b13e2c3d3f ubuntu "/bin/bash" 5 minutes ago Exited (0) 5 seconds ago root@lindell:~# docker start d1b13e2c3d3f root@lindell:~# docker exec -ti d1b13 /bin/bash root@d1b13e2c3d3f:/# uptime 01:39:46 up 1:18, 0 users, load average: 0.39, 0.39, 0.37 root@d1b13e2c3d3f:/#
On Part 2 of quick introduction to Docker, we will walk through using Dockerfile to automate image creation. We will see how quickly we can go from development to deployment.
You might also find some of the questions I answered in Stackoverflow about Docker.
No comments
You must be logged in to post a comment.