How to install and use Docker on Linux

Source: Internet
Author: User
Tags free ssl docker hub
This article mainly and everyone mainly introduces the installation and use of Docker on Linux method, small series feel very good, now share to everyone, hope to help everyone.

Docker makes it particularly easy to create, deploy, and manage containers. Better yet, installing and using Docker is especially handy on Linux platforms.

I'll show you how easy it is to install Docker on Linux and get you started with Docker. My demo platform is Ubuntu 16.04 Server, but the process is similar in most other Linux platforms.

I assume here that you have started Ubuntu Server 16.04.

Installation

Since Ubuntu Server 16.04 lacks a graphical interface, I will install and use Docker entirely from the command line. Before you install, you need to update apt and make the necessary upgrades. It is important to note that if the system kernel is upgraded, you will need to restart the system. So it's best to pick a time when the server can restart.

Run the following command to update apt:


sudo apt update

When you are finished, use the command to upgrade the system:


sudo apt upgrade

If the kernel is upgraded, you need to restart the server with the following command:


sudo reboot

If the kernel is not upgraded, you can install Docker (no reboot required). The commands for installing Docker are:


sudo apt install Docker.io

If you are using a different Linux distribution, you should install the Docker package when you try to install it with the appropriate package manager and find that there are no docker.io packages. For example, install the command on Fedora:


sudo DNF install Docker

If you are using CentOS 7, it is best to install Docker using the installation script. First use the command sudo yum check-update to update the system. Once the upgrade is complete, enter the following command to download and run the required script:


Curl-fssl https://get.docker.com/| Sh

By default, only Administrator privileges can run Docker commands. With security in mind, you don't want to run Docker with the root user or with sudo. To solve this problem, you need to add your own users to the Docker group. The command is as follows:


sudo usermod-a-G Docker $USER

When you're done, log out of the system and log back in again, and it should be done. However, if your platform is Fedora, adding users to the Docker group will find that the group does not exist. What should we do then? You need to create this group first. The command is as follows:


sudo groupadd docker && sudo gpasswd-a ${user} docker && sudo systemctl restart Dockernewgrp Docker

Log out before logging in. You can start using Docker.

Start, pause, and enable Docker

Once you have installed Docker, you can have the system automatically start the Docker daemon at startup. Use the following two commands to accomplish this:


sudo systemctl start Dockersudo systemctl enable Docker

If you need to pause or restart the Docker daemon, the command is:


sudo systemctl stop Dockersudo systemctl restart Docker

You can now deploy containers with Docker.

Pull Mirror

For Docker, mirroring is the cornerstone of building a container. You can pull down an image (like NGINX) and deploy any number of containers based on the image. Before using mirroring, you first need to pull the image into the system. The image is pulled from the registered repository, and by default Docker is installed with a default registered warehouse Docker hub--This registered repository contains a large number of images that others have contributed (both official images and user-contributed mirrors).

Suppose you want to pull an Nginx Web server-related image. Before you start pulling, check what mirrors are already in the system. Enter the docker images command and you will notice that there is no mirror present (Figure 1).

Figure 1: No mirrors yet.

Let's pull up a mirror. Use the following command to download the Nginx image from the Docker Hub:


Docker Pull Nginx

The above command will download the latest (official) Nginx image from the Docker Hub. Now run the Docker images command to see the list of mirrors (Figure 2).

Figure 2:nginx Image has been pulled down.

Notice what I'm saying here is the "official" Nginx image? There are many unofficial Nginx images on the Docker Hub. These unofficial images are created based on a variety of different purposes. You can use the following commands to search for all Nginx images in the Docker Hub:


Docker Search Nginx

You will find (in Figure 3) that there are many Nginx images created for different purposes (reverse proxy, PHP-FPM (LCTT): FastCGI process Manager FastCGI Processes manager is a phpfastcgi manager designed to FASTCG I process Management integrates into PHP package) features, Letsencrypt (LCTT: Free SSL project provided by ISRG), Bitnami, Nginx and Drupal used on Raspberry Pi, and many more).


Figure 3:docker The various NGINX images found on the Hub.

Suppose you want to download an Nginx image with a reverse proxy function, an unofficial mirror jwilder/nginx-proxy. So enter the following command to pull this image:


Docker Pull Jwilder/nginx-proxy

Then enter the docker images command to see the new pull down image (Figure 4).

Figure 4: There are two different NGINX images.

With caution in mind, I recommend using only the official image, after all you cannot determine whether the unofficial image contains malicious code.

Once you have the image, you can use it to deploy the container. Next time we'll talk about how to publish containers through these Nginx images.

Docker is a super-powerful system that makes your job easier and makes your company more scalable and flexible. Want to know what else Docker can do, run man Docker and read its help documentation.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.