[Cloud Native & Docker Basics] Installation and use of Docker (for beginners)

Hits: 0

🏡 Blog Homepage: Pai Daxing

⛳️ Welcome to follow ❤️ Like 🎒 Favorites ✏️ Comment

🎢 This article was originally edited by Pai Daxing

🚧 Columns: [Docker] — Cloud Native

🎈 This series records the first exploration and in-depth thinking process of containerization technology. If there are any mistakes in the description, I hope you can give me some advice

Article directory

🍒 What is Docker

Docker is implemented based on the Linux kernel. Docker first adopted LXC technology. LXC is a container technology natively supported by Linux, which can provide lightweight virtualization. Docker is developed based on LXC, providing advanced packaging of LXC, standard configuration methods, On the basis of LXC, Docker provides a series of more powerful functions. And virtualization technology, such as KVM, is based on module implementation, and later Docker changed to its own developed and open source runc technology to run containers

🥕 The advantages of Docker

  • Rapid deployment: Hundreds of thousands of applications can be deployed in a short period of time, and delivered online faster
  • Efficient virtualization: no need for hypervisorsupport, Linuximplement application virtual machine based on kernel, greatly improve performance and efficiency compared to virtual machine
  • Savings: Improve server utilization, reduce IT support
  • Simplified configuration: package and save the running environment to the container, and start it directly when using it
  • Environment Unification: Standardize and unify the development, testing, and generated application operating environments to reduce various problems caused by different environments

🍠 Disadvantages of Docker

  • Isolation: Multiple containers share the kernel of the host, and the isolation between applications is not as complete as that of virtual machines

The basic components of Docker

  • Docker host (Host): a physical machine or virtual machine, used to run Dockerservice processes and containers, also become a host, nodenode
  • Docker server (Server): Docker daemon, running Docker containers
  • Docker Client (Client): The client uses dockercommands or other tools to calldocker API
  • Docker Warehouse (Registry): Warehouse for saving images, official warehouse :hub.docker.com, private warehouse can be builtharbor
  • Docker image (Images): An image can be understood as a model used to create an instance, equivalent to a package, through RPMwhich DEBmultiple containers can be created (the final service runs)
  • Docker container (Container): A container is a service or a group of services that is generated from an image and provides services to the outside world. It is equivalent to RPMrunning a program in a package. A container can be understood as a simple Linuxsystem .

🥝 Docker installation and use

First of all, before learning to install Docker, we must first learn how to uninstall Docker, in case there is an old version of Docker in the virtual machine, causing some unnecessary problems during the installation process.

① Uninstall the old version

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

② Docker installation steps

Download the required installation package

yum install -y yum-utils

Set up the mirror warehouse for installing Docker. The system defaults to foreign mirrors. You can also choose the best domestic Alibaba Cloud mirrors ( recommended )

# Default is foreign mirror
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux /centos/docker-ce.repo # ( not recommended)

#aliyunmirror
yum-config-manager \
    --add-repo \
    http: //mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #Recommended

Install Docker related engines

yum install docker-ce docker-ce-cli containerd.io

After the installation is complete, you can start Docker and use the command to check whether the installation is successful

# Start Docker 
systemctl  start docker 

# Determine whether the installation is successful 
docker  version

🍇 Create and start a container (RabbitMQ)

Pull the RabbitMQ image

docker pull rabbitmq

Create and run RabbitMQ

docker run -d -p 15672:15672 -p 5672:5672 \
    -e RABBITMQ_DEFAULT_VHOST=my_vhost  \
    -e RABBITMQ_DEFAULT_USER=admin \
    -e RABBITMQ_DEFAULT_PASS=admin \
    --hostname myRabbit \
    --name rabbitmq \
    rabbitmq

Command introduction:

  • -d: Indicates running the container in the background
  • -e: Specify environment variables
    • RABBITMQ_DEFAULT_VHOST: Default virtual machine name;
    • RABBITMQ_DEFAULT_USER: Default username;
    • RABBITMQ_DEFAULT_PASS: Default user password;
  • --name rabbitmq: set the container name
  • rabbitmq: The container uses the image name

View container startup statusdocker ps

Set up RabbitMQ to start automatically when Docker starts

docker update rabbitmq --restart=always

Start the rabbitmq_managementvisualization plugin

method one:

docker exec -it rabbitmq rabbitmq-plugins enable rabbitmq_management

Method Two:

docker exec -it rabbitmq /bin/bash
---------------------------------
user@7b295c46c99d /: rabbitmq-plugins enable rabbitmq_management

Access the RabbitMQ background management visual interface http://ip:15672. The default username and password for the first login are bothguest

Before accessing, you need to open the firewall and expose the port for access

firewall-cmd --zone=public --add-port=15672/tcp --permanent        
firewall-cmd --reload

🔔🔔 E n d i n g 🔔🔔 🔔 🔔Ending 🔔 🔔 🔔🔔Ending🔔🔔

You may also like...

Leave a Reply

Your email address will not be published.