In this post, I’ll try my best to explain to you what Docker Technology is, and how you can use it as well!
What is Docker?
Layman Terms : Imagine that your laptop is the whale, and the containers you see are software packages. Basically, you can run a lot of different software packages on your system that don’t clash with each other.
Programmer’s Terms : Docker gives you OS-level virtualization and also has the ability to install various different software packages without worrying about maintaining different virtual environments for each of them. Also provides you with all the functionalities except the “front-end” of the OS. Everything is done through CLI (command-line-interface).
Example : You can run Ubuntu OS on your Windows laptop without having to install a VM. You just need the Docker image for Ubuntu that is open-sourced on DockerHub. (There will be no Graphical UI, just the Terminal)
Uses of Docker :
- Helps packaging a software which can easily be replicated on another system.
- Saves the time of installing the dependencies of the software and is well-isolated from your system.
- Enables you to deploy the software easily (reusable) and automate a lot of processes.
- Helps you build complex Docker applications that can communicate with each other.
- You can replicate different environments and frameworks within the Docker to test your application on!
Common Terms used with Docker :
-
Docker Image :
A Docker image is a file, comprised of multiple layers, that is used to execute code in a Docker container. An image is essentially built from the instructions for a complete and executable version of an application, which relies on the host OS kernel. When the Docker user runs an image, it can become one or multiple instances of that container. -
Docker Container :
Containers are a standardized unit of software that allows developers to isolate their app from its environment, solving the “it works on my machine” headache. A Docker Container is a running instance of a Docker Image which is created when requested. The applications run inside the Docker Container which is very well abstracted from the host OS. -
Layers :
A Docker Image is built with layers of code, environment variables, libraries, tools, dependencies or other Docker Images. You can either create an entirely new Docker Image, or you can use existing Docker Images (like Ubuntu) as your base layer and add your software on top of that. -
DockerHub :
Dockerhub is an online platform to publish your Docker Images and make it accessible to the world! It is very similar to Github where you upload your code and maintain versions of it. On Dockerhub, you can explore other Docker Images, upload your own and maintain them. -
Containerization :
It is process of bundling your software application together with all of it’s config files, dependencies, libraries so that anyone can run your software on different OS efficiently and most importantly bug-free.
Get Started with Docker :
Here’s a quick walkthrough on how you can setup Docker and run Ubuntu 18.04 on your system.
-
Docker Installation :
The official Docker installation is very detailed and simple enough to follow. You can find links to Ubuntu, MacOS, Windows. -
Docker Commands to install Ubuntu 18.04:
- To download the Ubuntu Image onto your system:
sudo docker pull ubuntu:18.04
- To create a container of the Docker Image and attach it to terminal:
sudo docker run -it ubuntu:18.04
The ‘it’ flag is actually two separate flags, ‘-i’ for interactive and ‘-t’ is attach a terminal to interact with the container. Now you should be able to run any Ubuntu commands and add your code to the container. - To exit from the container run :
exit
: To stop running the container and exit.
OR
CTRL+P+Q
: To just close the interactive terminal but keep the container running in the background. - To see a list of Docker Images :
sudo docker images
- To see a list of all Docker Containers :
sudo docker ps -a
where the -a is the ‘all’ flag. - To start a container that’s not running :
sudo docker start container_ID
where container_ID is the container ID that you want to run and is obtained from the previous command.
- To download the Ubuntu Image onto your system:
Useful links :
Conclusion :
Containers are already being used at scale in a lot of real-world applications and containerization is an important skill to have moving forward if you are into software development. Hope you learned something from this! If you made it this far, do like the post and share it with others!