Coder Social home page Coder Social logo

docker-introduction's Introduction

Introduction to Docker

Imagine that you have developed your open-source application and pushed the project to GitHub. After a week when you check your email, you see that there are several emails about your last project from people who failed to run your project. When you check their issues you realize that each one of them has a different problem, one with the dependencies versions, the other with the configuration settings and so on. How can you solve this problem? By writing a long boring installation guide? This may help but will not solve the problem. Here is where Docker comes to the rescue.

What is Docker?

Let's start with the official definition from the Docker documentation:

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly.

This means that by using Docker, if an application works on your development machine, it can run in the same way on other machines. But how can this happen? By packaging the application with all its requirements and passing it to an isolated environment called Container. It allows multiple applications use different versions of some software along with each other in the same machine without messing with each other.

applications use different versions

Dockerizing an application

A Dockerized application is an application that Dockerfile has been added to it. Dockerfile is a plain text file which includes instructions that Docker uses to package up an application into an image. This image contains everything the application needs to run such as:

  • A cut-down operating system
  • A runtime environment (eg Python)
  • Application Files
  • Third-party libraries
  • Environment variables

Therefore, if people get our project, they don't have to spend hours on installing dependencies and setting configurations! They just have to run a single command.

Virtual Machines vs Containers

Virtual Machine is an abstraction of a machine (physical hardware) while Container is an isolated environment for running an application. The following table shows some of their differences:

Virtual Machines Containers
Each VM needs a full-blown OS. All containers share the OS of the host.
Slow to start Start quickly
Need more hardware resources. Need less hardware resources.

Virtual Environments

In some programming languages like Python, there is a similar concept called virtual environment. From the Python documentation:

A virtual environment is an isolated Python environment where a project’s dependencies are installed in a different directory from those installed in the system’s default Python path and other virtual environments.

Here is a nice picture describes the differences between the VM, VE and Docker Container architecture:

VM, VE & Container Differences

Architecture of Docker

Docker uses a client-server architecture. The client component talks to the Docker Engine (server component) through a RESTful API. Docker Engine takes care of building, running, and distributing Docker containers.

Architecture of Docker

Installing Docker

You can download and install Docker on multiple platforms such as macOS, Windows and Linux. Docker Engine is available on Mac and Windows through Docker Desktop which is the combination of Docker Engine plus a bunch of other tools. There is a complete guide on the installation in the Docker official documentation, based on your operating system go to one of the following links:

After the installation, open the terminal and run this command:

$ docker version

You must see the Client version and the Server version in the terminal; otherwise, Docker is not installed correctly on your machine.

A Simple Example

  1. Create a directory named hello-world.

  2. In the directory create a file named app.js and put the code below in it.

    console.log("Hello World!")
  3. Create the Dockerfile and put the code below in it.

    FROM node:alpine
    COPY . /app
    WORKDIR /app
    CMD node app.js
  4. Open the terminal in the directory and execute the following command:

    $ docker build -t hello-world .
  5. Now, guess what is the output of this command:

    $ docker run hello-world
    See the answer

    Hello World!
    

docker-introduction's People

Contributors

safinal avatar

Stargazers

Pedram Yamini avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.