1. What is Docker

This development tool with cute dolphin logo is our C-bit big guy today — Docker. Let’s take a look at the definition of Docker on the Internet:

“Docker is an open source application container engine that allows developers to package their applications and dependencies into portable containers and distribute them on any popular Linux machine, as well as virtualization. Containers are completely sandboxed and have no interface with each other.”

Don’t get it? Don’t understand the right! Hahahahahahaha, feel the sarcasm from programmers!

The main reason for this confusion is the introduction of a new concept: containers. At first many people will put the container and the traditional confused the concept of virtual machine, a lot of people should be used virtual machines, each virtual machine has its own full user operating system, the virtual machine once open, preassigned ration it resources are all occupied, but the container and we are hosting a Shared hardware resources and the operating system, can realize the dynamic allocation of resources.

Simply put, container technology is a way to virtualize operating systems, allowing us to run applications with extreme dependencies in resource-isolated processes.

Docker can help you pack your application and its dependencies into a single file. Running this file generates a virtual container. When we run this program in a virtual container, it looks just like running it on a real physical machine.

In general, Docker allows users to easily create and use containers and run their applications in containers, which can achieve environmental consistency, improve operational efficiency and productivity of developers. It also helps you to version, copy, share, and modify it just like you would normal code.

We can clearly see the advantages of containers over traditional virtual machine features in the following table:

2. Why docker?

After briefly introducing the concepts of containers and virtual machines, we can roughly sum up the following advantages of Docker:

(1) It can help us install applications flexibly and conveniently, build an environment and deploy applications.

(2) Compared with the traditional virtualization way, it saves system resource overhead, almost no performance loss, and fast startup, the memory is very small, more lightweight, you can make more hard disk space to store small movies. In the same hardware environment, the number of images running Docker is far more than the number of virtual machines, and the utilization rate of the system is very high.

(3) flexible migration of your development of the application, it can ensure that the application fast, reliable, consistent deployment, and not affected by the deployment environment, we do not have to worry about the environment.

(4) Finally, and most importantly, directly linked to our wallets. Learning Docker can make you more competitive in job hunting. At present, Docker enjoys a good development in the Domestic Internet industry, especially in first-line companies. The use of Docker has become very common, and even becomes a plus in the interview of enterprises. Familiarity with Docker is a requirement in many development engineer recruitment requirements.

At present, there are many excellent Docker tutorials on the network, but many of them are primitive things, I also see the cloud in the fog, it is still difficult for beginners to understand, below I will from the perspective of the primary front-end development engineer, a simple summary of using Docker to deploy mongodb database and open remote connection. I hope this small case can inspire your interest in learning Docker and give you a preliminary understanding of this powerful development tool.

The three basic concepts of Docker

Image (mirror)

The Container (containers)

The Repository (warehouse)

Image (mirror)

Don’t understand what a mirror is? It doesn’t matter, don’t understand, don’t understand, continue to read.

(Don’t ask me why I don’t explain, let’s keep some honesty and shame)

Docker Container

Docker container is the running instance of Docker image, which is the place where the project program is really run, system resources are consumed and services are provided.

Docker provides a set of simple and practical commands to create and update the image, we can directly download a created application image through the network, and use the Docker RUN command directly.

When the image is successfully RUN, the image is a Docker container.

Container can be understood as a lightweight sandbox. Docker uses containers to run and isolate applications. Containers can be started, stopped and deleted without affecting Docker images.

The Repository (warehouse)

A Docker repository is a centralized repository for image files. Once the image is built, it can easily run on the current host.

However, if we need to use the image on other servers, we need a centralized service to store and distribute the image, and Docker Registry is such a service.

Repository and Registry are sometimes confused, but not strictly distinguished.

The repository Registry can be understood as a hosting service like GitHub.

In fact, a Docker Registry can contain multiple repositories. Each Repository can contain multiple tags, and each Tag corresponds to an image.

Therefore, the mirror repository is the place where Docker centrally stores image files, similar to the code repository we used before.

When we run docker push, Docker pull, and Docker search commands locally, we actually communicate with the Docker Registry through the Docker Daemon.

Image is the premise of Docker running container, warehouse is the place to store image, visible image is the core of Docker.

3. Install Docker

Blowing for a long time finally started to get to the point, first let’s log in its official website

www.docker.com/

I can’t help calling the Docker design team crazily. Its official website is one of the most visually stunning and interactive sites I’ve seen so far. The overall feeling is very fresh and fast, which fits well with the function and concept of this tool. I fell in love with it at first sight, just like love.

Click on Learn More for a full description

Click “Start a free trail” to create a free account

Create an account and log in. Click on the right side.

Go to https://hub.docker.com/ and click “Get Start with Docker Desktop” to enter the download page.

Select a version based on your operating system and download it to the local PC. It also provides you with some small tutorials. Follow the five steps on the left step by step to get the basic operation of Docker.

After downloading and installing the computer will appear in the upper right corner of the cute little dolphin logo.

Open the terminal and run the docker -v command to check the currently installed docker version. When the output: Docker version 18.09.2, build 6247962 (version number) is printed, it means that it has been successfully installed and can be used.

We check all images supported by Docker on this page of Docker official website, and we can see that nodeJS, mySQL, mongoDB and PHP are all provided.

Hub.docker.com/search?imag…

Click to enter the corresponding page to view the existing mirror version

Next is going to introduce another big man mongoDB database, before not encountered Docker, install mongoDB process can write a bitter history, not only did not install good also changed the environment variables (here to give you a close tip: before modifying important parameters must be backed up! Be sure to back up! Be sure to back up!) I would like to thank my college friend who told me about Docker and saved my receding hairline. With Docker, the whole process is silky and smooth, eliminating a series of tedious links such as configuration, bash_profile and so on.

Because the Docker server is in foreign countries, in order to ensure that our next download experience is more sour and cool, before starting to get a domestic mirror, here again blow a wave of Jack Ma dad, Ali cloud really sweet!

It opens at

Cr.console.aliyun.com/?spm=5176.1…

Register your account and log in

Find products and Services – Elastic Computing – Container Image Services in the hamburger navigation in the upper left corner.

Then select the bottom menu bar, image accelerator, and select your corresponding operating system on the left page. The default is Ubuntu. At the beginning, I did not understand it for a long time and began to doubt life. Who would have thought that a TAB that doesn’t look like a TAB is clickable? Switch between Mac and Windows manually.

We have installed Docker just now, so we can directly follow the following steps written on the website. (What I wrote here is the operation procedure of Mac system, you can see that aliyun official website also recommends using Docker by default!!)

For Docker for Mac installed users, you can refer to the following configuration steps:

Right-click the Docker icon in the top bar of the desktop, select Preferences, and select The Registry mirrors list under the Daemon TAB (Advanced TAB before Docker 17.03)

8 p0vcewm.mirror.aliyuncs.com added to the array “registry – mirrors”, click Apply & Restart button, wait for Restart Docker and application configuration image of accelerator.

After the image file is configured in docker, we go back to the terminal and execute the Docker pull mongo command to load the mongoDB database image to our local. By default, the latest version will be downloaded. If you need a specific version number, add a colon after the command and write the version number, for example, docker pull mongo:3.6, download the 3.6 mongoDB database.

The latest version of mySQL database may have some unstable functions, it is recommended not to install the latest version, but mongoDB does not, so directly execute docker pull mongo to download it.

Run Docker Images to see all the images we pulled locally. TAG shows the current version information.

To remove the image just run the Docker RMi Mongo: version number

Docker run –name some-mongo -p 27017:27017 -d mongo docker run –name some-mongo -p 27017:27017 -d mongo

This command starts a container with the mongodb image, named some-Mongo, and mapped to port 27017.

This error will be reported if you do not expose the 27017 port number when connecting in Node.js, indicating that you cannot find the port number.

After starting the container, run docker ps -a to check all started containers. Ensure that the STATUS of the container is not in the Exited blocked state. If it is blocked, run docker restart container ID or container name to restart the container. The command to stop a container is the Docker stop container ID or container name.

Docker exec-it some-mongo bash docker exec-it some-mongo bash docker exec-it some-mongo bash docker exec-it some-mongo bash

Common Docker commands

We can view the detailed help document of the command through docker-h. Here I’ve put together a list of some of the commands that we might use a lot on a daily basis.

Docker pull image_name: Pulls a docker image

Docker images: View the images that exist under the host

Docker ps -a: Check the status of the current container (-a is to check the status of all containers, including not running)

Docker restart The container name or ID: restarts the container

Docker stop container name or ID: Stop container

Docker rmI image_name: delete image (stop container first)

Ok, the above is the initial contact with Docker experience, simple sorting and sharing, I wish you a happy eating!