Docker for beginners - presentation

~ Docker ~

I- Introduction
II- Docker presentation
III- A simple [MySQL / phpMyAdmin] docker example
IV- Docker in Windows, how to ?
V- Simple Docker glossary
VI- Links


I- Introduction


There are enough websites to introduce to you Docker in detail. This presentation will just remind you the key concepts of Docker. In my posts, I will always talk about Docker embedded in the Windows environment but I presume, all given information will also be valid for Linux and other OS.

So, what are we going to see in this post ?
As I said, we will remind the key concept of Docker, then we will list some common use cases and all the basic related commands. I will share some links at the end of the post if you want to go deeper with Docker. Let's go !


II- Presentation


Docker is 'just' a technology used to virtualize environments (named containers) in order to run specific applications. It acts like traditional virtual machine but it's much more lightweight. Take a look at the following diagram:
- Both VMs and containers will be installed on a (dedicated) machine. For Docker, we talk about a Docker machine.  In my case, I will use a Windows PC. Docker engine will (after being installed as we will see just after), comes in place of the traditional Hypervisor.

- Over the 'Docker engine' layer, we will setup containers. Containers are isolated spaces that contain only libraries used to execute wanted applications or services. So it's much more lightweight / easy to configure. You don't need to install a full OS anymore.

- In a container, you can install applications (like MySql) or services (like nodejs). To install wanted applications, you will surely use Docker images. There are already many available images on Docker hub website (see links at bottom).


III- A simple [MySQL / phpMyadmin] docker example


Scenario 1: using a MySQL database

Imagine, you are working on a project (a Windows one) that use a database like MySQL.
To setup / test your application you have several possibilities:

- you own a remote Linux server that you can use to install a MySQL instance on. So you have to configure your server, then install MySQL then you need to restore Dumps and configure it to be accessed from the outside.

- you can do the same with a cloud service like Azure

- or you can install on your Windows development machine, something like a WAMP server, then configure it.

You will need to do something like that:
Using a Linux Server (can be a Virtual Machine)


>> You can see that:
- you need to get access to a Linux server (it can be a virtual machine)
- there are many (traditional) steps to setup, configure, securize, backup your server and SQL instance.
- then your development environment must have access to this Linux server. Sometimes, it's not so obvious because of network configuration...

Here is what you can get with Docker:

Using Docker containers on Windows

>> Now you can see that you just need one environment:
- it's faster to setup
- but it's also faster to backup if needed
- Containers need less resources than a traditional VM.
- Pre requisite is to install Docker engine



Scenario 2: managing your Database with phpMyAdmin

Ok that's cool, but I need to manage my Database. In Docker, you still have several possibilities to do that, like on a real Linux server:
- using a batch composing your SQL commands
- or using a tool like phpMyAdmin

Using MySQL batch

docker exec -it expdb_db_1 mysql -u root -p




This simple command enables you to type your SQL Commands from a command prompt. Note how we connect to the 'MySQL container' using "docker exec"...


Installing a new container: PhpMyAdmin

But you can also install a new docker container with PhpMyAdmin !
It's really fast and  you just have to configure it to target the existing MySQL database.
Adding new container: PhpMyAdmin

And,  in a very few steps, we get access to our MySQL database using a new container:

phpMyAdmin container installed in a few clicks


IV- Docker in Windows, how to ?

Download Docker for Windows

Using Docker in Windows is pretty easy. The first step is to install Docker Engine on your machine. For that you can go directly here, every steps are well explained (package size about 500Mb):
>> https://hub.docker.com/editions/community/docker-ce-desktop-windows

Docker engine installed

Docker service running on Windows

Docker Hub

Then you can create an account on Docker Hub, the entry point for all your Docker's images:
>> https://hub.docker.com/




Getting started guide

Then follow this "Getting started" guide:
>> https://docs.docker.com/docker-for-windows/



Kinematic client to manage your containers

There is a Windows tool to manage your container. It's the Docker Toolbox called Kinematic:

Kinematic - Docker Toolbox


V- Simple Docker Glossary

Here are a few words you will always see going deeper into Docker.


Docker machine:
This is the host machine for the Docker engine. You will install your containers on this machine

Docker Image:
An image represent an application / service you want to install as a Docker container. Image embed minimum required libraries in order to make you application executable.

Container:
The container is an (configured) instance of a given image on your Docker machine.

Docker file:
This is a file grouping a set of commands needed to generate a container from a given Docker image.

Docker-compose:
It is a tool that you will surely use later, to define and execute multiple containers. These containers can "communicate" so Docker-compose also enables you to configure containers networks and volumes to store shared data.
When your compose file is set up, you just need one command to execute all of your configured containers.


More, more, more... here: https://docs.docker.com/glossary/


VI- Links


(FR) Good introduction: 
https://bacarybruno.me/docker-premieres-impressions/

Docker hub image repository: 
https://hub.docker.com/search?q=&type=image

Official Docker configuration:
https://docs.docker.com/get-started/

Kinematic (client to manage your containers):
https://kitematic.com/

Docker compose:
https://docs.docker.com/compose/



So that's it, now you can go deeper into Docker ! 😎💹

0 commentaires: