1024programmer Blog Docker Note 1_To hide a blog

Docker Note 1_To hide a blog

class=”markdown_views prism-atom-one-dark”>

Docker Note 1

Looking at the learning video is the up master: Meeting the Mad God

If you want to learn operation and maintenance, learn CI/CD, you can’t do without Docker.

1. Install Docker from 0

System: CentOS7

Yum sets Aliyun source, yum source update: (If this step is skipped, an error will be reported when starting Docker later)

# Backup
 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

 yum clean all
 yum makecache
 yum update
 

Install Docker:

# Uninstall the old version
 yum remove docker \
 docker-client \
 docker-client-latest \
 docker-common \
 docker-latest \
 docker-latest-logrotate \
 docker-logrotate \
 docker-engine
                  
 # Install Toolkit
 yum install -y yum-utils \
 device-mapper-persistent-data \
 lvm2

 # Set up Aliyun warehouse
 yum-config-manager \
 --add-repo \
 http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

 # Install Community Edition
 yum install docker-ce docker-ce-cli containerd.io
 

Check if the installation is successful:

# Start Docker
 systemctl start docker
 # run hello world
 # The docker run command will first check whether this image exists, and if it does not exist, it will go to the warehouse to pull it
 #Create a container from this image, this container runs an executable file, the executable file can produce the output you are currently seeing
 docker run hello-world
 

image-20210715112709497

Second, uninstall Docker (do not want to learn to uninstall again)

yum remove docker-ce
 rm -rf /var/lib/docker
 

3. Introduction to Docker

3.1 Advantages of Docker

Docker is an open platform for developing, delivering and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure the same way you manage your applications. By leveraging Docker’s approach to rapidly delivering, testing, and deploying code, you can drastically reduce the delay between writing code and running it in production.

1. Deliver your application quickly and consistently

Docker simplifies the development lifecycle by allowing developers to work in a standardized environment using local containers of the application or service you provide.

Containers are well suited for continuous integration and continuous delivery (CI/CD) workflows, consider the following example scenarios:

  • Your developers write code locally and share their work with colleagues using Docker containers.
  • They use Docker to push their applications into a test environment and perform automated or manual testing.
  • When developers find bugs, they can fix them in the development environment and redeploy them to the test environment for testing and verification.
  • After testing is complete, pushing the patch to production is as easy as pushing an updated image to production.
2. Responsive deployment and expansion

Docker is a container-based platform that allows for highly portable workloads. Docker containers can run on a developer’s local machine, on a physical or virtual machine in a data center, on a cloud service, or in a hybrid environment.

Docker’s portability and lightweight nature also make it easy for you to dynamically manage workloads and scale up or tear down applications and services in real time as business needs dictate.

3. Run more workloads on the same hardware

Docker is light and fast. It is based on virtual80 tomcat

image-20210716133935711

It is already accessible at this time, but what we want to see is not such a page.

This is because the Alibaba Cloud image downloads an incomplete image for us, eliminating unnecessary things.

Enter the container and find that there is nothing in the webapps folder:

[root@centos ~]# docker exec -it tomcat_test /bin/bash
 root@25518e91b2db:/usr/local/tomcat# ls
 BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist
 CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work
 root@25518e91b2db:/usr/local/tomcat# cd webapps
 root@25518e91b2db:/usr/local/tomcat/webapps# ls
 root@25518e91b2db:/usr/local/tomcat/webapps#
 

Copy the files in webapps.dist to webapps:

root@25518e91b2db:/usr/local/tomcat# cp -r webapps.dist/* webapps
 root@25518e91b2db:/usr/local/tomcat# cd webapps
 root@25518e91b2db:/usr/local/tomcat/webapps# ls
 ROOT docs examples host-manager manager
 

Visit again:

image-20210716135300463

7.3, ES and Kibana (visualization tool for ES)

Both Nginx and Tomcat only expose one port, while ES exposes more ports.

docker pull elasticsearch:7.6.2

 # Stop other containers before running (because ES consumes a lot of memory)
 docker stop $(docker ps -q)

 # Run ES (after executing this command, the terminal will become very stuck, because I only allocated 2G memory to the virtual machine)
 # I don’t know why the container stopped automatically after about a minute after this command was executed (there is a solution later)
 docker run -it --name elasticsearch -d -p 9200:9200 -p 9300:9300 -p 5601:5601 elasticsearch:7.6.2

 # Run Kibana (consistent with ES version)
 docker run --link elasticsearch:elasticsearch -p 5601:5601 -d kibana:7.6.2
 

Use docker stats to view memory usage:

[root@centos ~]# docker stats
 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
 b7cfa47e7f8d elasticsearch 0.08% 964.9MiB / 1.777GiB  53.04% 656B / 0B 718MB / 0B 18
 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
 b7cfa47e7f8d elasticsearch 0.08% 964.9MiB / 1.777GiB  53.04% 656B / 0B 718MB / 0B 18
 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
 b7cfa47e7f8d elasticsearch 39.01% 961.1MiB / 1.777GiB  52.83% 656B / 0B 736MB / 0B 18
 

Solve the problem of ES automatically stopping:

# run with this command (limit memory)
 docker run --name elasticsearch -d -e ES_JAVA_OPTS=  "-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200  :9200 -p 9300:9300 elasticsearch:7.6.2
 

Check if ES starts successfully:

image-20210716151147244

Check whether Kibana is started successfully:

image-20210716152426089

8. Docker visualization

Use portainer first (Docker graphical interface management tool, lightweight), and then use Rancher later.

docker run -d -p 9000:9000 \
 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=  true portainer/portainer
 

image-20210716153301131

In this way, the operation is successful, and the next step is to use it.

Log in first, like this:

image-20210716153459096

Select Local to connect to the local container:

image-20210716153927788

Click connect:

Then explore on your own. (Usually you don’t need this visualization tool, just use commands)

See if Kibana starts successfully:

image-20210716152426089

8. Docker visualization

Use portainer first (Docker graphical interface management tool, lightweight), and then use Rancher later.

docker run -d -p 9000:9000 \
 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=  true portainer/portainer
 

image-20210716153301131

In this way, the operation is successful, and the next step is to use it.

Log in first, like this:

image-20210716153459096

Select Local to connect to the local container:

image-20210716153927788

Click connect:

Then explore on your own. (Usually you don’t need this visualization tool, just use commands)

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/docker-note-1_to-hide-a-blog-3/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索