In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you the relevant knowledge points about the analysis of Docker instances installed under CentOS7.5. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Introduction to docker
Docker is an open source container engine that helps deliver applications faster. Docker isolates the application from the infrastructure layer and manages the infrastructure as if it were a program.
With docker, applications can be packaged, tested, and deployed faster, and the cycle from writing to deploying running code can be shortened.
The advantages of docker are as follows:
1. Simplify the procedure
Docker allows developers to package their applications and dependency packages into a portable container and publish them to any popular linux machine for virtualization. Docker has changed the way it is virtualized, allowing developers to manage their work directly in docker. Convenience and rapidity is already the biggest advantage of docker. In the past, tasks that took days or even weeks could be completed in seconds under the docker container.
2. Avoid choice phobia
If you have choice phobia, you are a senior patient. Docker helps you pack up your entanglements! For example, docker image; docker image contains the running environment and configuration, so docker can simplify the deployment of multiple application instances. For example, web applications, background applications, database applications, big data applications such as hadoop cluster, message queue and so on can be packaged into a mirror deployment.
3. Save money
On the one hand, with the advent of the era of cloud computing, developers do not have to configure high hardware in order to pursue results, and docker has changed the mindset of high performance and high price. The combination of docker and cloud makes the cloud space more fully utilized. It not only solves the problem of hardware management, but also changes the way of virtualization.
Architecture of docker
Docker daemon (docker daemon)
Docker daemon is a background process running on a host (docker-host). You can communicate with it through the docker client.
Client (docker client)
The docker client is the user interface of docker, which accepts user commands and configuration identities, and communicates with docker daemon. In the figure, docker build and so on are related commands of docker.
Images (docker Mirror)
The docker image is a read-only template that contains instructions for creating a docker container. It is similar to the system installation CD, where you can install the system using the system installation CD. Similarly, you can use the docker image to run the programs in the docker image.
Container (container)
The container is a runnable instance of the mirror. The relationship between mirrors and containers is somewhat similar to that between classes and objects in object-oriented. You can use docker api or cli commands to start, stop, move, and delete containers.
Registry
Docker registry is a service that centrally stores and distributes images. After the docker image is built, it can be run on the current host. But if you want to run this image on another machine, you need to copy it manually. At this point, you can use docker registry to avoid manual replication of the mirror.
A docker registry can contain multiple docker repositories, and each repository can contain multiple image tags, each corresponding to an docker image. This is similar to the maven repository. If docker registry is compared to the maven repository, then the docker repository can be understood as the path of a jar package, while the mirror tag can be understood as the version number of the jar package.
Docker registry can be divided into public docker registry and private docker registry. The most commonly used docker registry is the official docker hub, which is also the default docker registry. There are a large number of excellent images stored on docker hub, which we can download and use using the docker command.
Installation of docker
Docker is an open source commercial product with two versions: community edition (ce) and enterprise edition (ee). The enterprise version includes some paid services that individual developers generally don't need. The following introductions are for the community version.
For the installation of docker ce, please refer to the official documentation. Here we take centos as an example:
1. Docker requires that the kernel version of the centos system is higher than 3.10.
Check your current kernel version with the uname-r command
# uname-r
View operating system version
# cat / etc/redhat-release
2. Uninstall the old version (if the old version was installed)
# yum remove docker docker-common docker-selinux docker-engine
3. View the yum source address
# yum repolist
4. Set the yum source and update the package index of yum
# yum-config-manager-- add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# yum makecache fast
5. You can view all docker versions in all repositories and select a specific version to install
# yum list docker-ce-- showduplicates | sort-r
6. Install docker
# yum install docker-ce # since only stable repository is enabled by default in repo, stable version 18.03.1 is installed here
# yum install # for example: yum-y install docker-ce-18.03.1.ce
7. Start and join the boot boot
# systemctl start docker
# systemctl enable docker
8. Verify whether the installation is successful (both client and service indicate that the docker installation starts successfully)
# docker version
9. Uninstall docker
# yum-y remove docker-engine
Docker common commands
Mirror related commands
1. Search for images
You can use the docker search command to search for images stored in docker hub. After executing this command, docker searches docker hub for image repositories that contain the keyword tomcat.
The above list contains five columns with the following meanings:
-name: image repository name.
-description: image repository description.
-stars: the number of collections in the image repository, indicating the popularity of the image repository, similar to github's stars0
-offical: indicates whether it is an official repository. The images marked [0k] in this column are created and maintained by the official project team of each software.
-automated: indicates whether it is an automatically built image repository.
2. Download the image
Use the command docker pull command to download the image from the docker registry. After executing this command, docker downloads the latest version of the tomcat image from the tomcat repository in docker hub. If you want to download the specified version, add a colon after the tomcat to specify the version, for example: docker pull tomcat:7
# docker pull tomcat:7
3. List the images
Use the docker images command to list the downloaded images
# docker images
The above list means as follows
-repository: the name of the repository to which the image belongs.
-tag: image tag. The default is latest, which means up to date.
-image id: image id, which indicates the unique ID of the image.
-created: time when the image was created.
-size: image size.
4. Delete the local image
Use the docker rmi command to delete the specified image
# docker rmi tomcat:7
Container related commands
1. Create and start the container
Use the following docker run command to create and start a container, which is the most commonly used command, which has many options, some of which are listed below.
-d option: indicates running in the background
-p option: specify port mapping
-- hostport:containerport
# docker run-d-p 808080 tomcat:7
This starts a tomcat container. In this example, two parameters are added to docker run, which mean as follows:
-d running in the background
-p Host Port: container Port
Here, port 8080 of the container is mapped to port 8080 of the virtual machine, which can also be accessed through the browser that comes with the virtual machine or the ip:8080 of the physical machine that accesses the virtual machine (192.168.126.128).
When you visit the http://docker host ip:8080/, you will see the main interface of tomcat as follows:
It is important to note that when you use the docker run command to create a container, you will first check whether the specified image exists locally. If no image with that name exists locally, docker automatically downloads the image from docker hub and launches a docker container.
2. List containers
Use the docker ps command to list the containers that are running
# docker ps
To list all containers, including those that have been stopped, use the-a parameter. The list contains seven columns, meaning as follows
-container_id: indicates the container id.
-image: indicates the image name.
-command: indicates the command that runs when the container is started.
-created: indicates the creation time of the container.
-status: indicates the running status of the container. Up indicates that it is running, and exited indicates that it has stopped.
-ports: indicates the external port number of the container.
-names: indicates the container name. The name is automatically generated by docker by default, or you can specify it by yourself using the-name option of the docker run command.
3. Stop the container
Use the docker stop command to stop the container
# docker stop4dbf26d1624d
Where 4dbf26d1624d is the container id. Of course, you can also use the docker stop container name to stop specifying the container.
4. Start the stopped container
Using the docker run command, you can create a new container and start it. For stopped containers, use the docker start command to start
# docker start4dbf26d1624d
5. View the container log
# docker container logs 4dbf26d1624d
6. Enter the container
Use the docker exec command to enter a running docker container. If the docker run command runs the container without using the-it parameter, use this command to enter the container. Once you have entered the container, you can execute the command in the container's shell
# docker exec-it 4dbf26d1624d / bin/bash
Exit the container
# exit
7. Delete the container
Use the docker rm command to delete the specified container
# docker rm4dbf26d1624d
This command can only delete stopped containers. To delete running containers, use the-f parameter
Principle of docker Virtualization
Comparison of traditional virtualization and container technology structures:
The traditional virtualization technology realizes virtualization at the hardware level, increases the link of the system call link, and has performance loss.
Container virtualization technology is implemented in a shared kernel with almost no performance loss.
These are all the contents of the article "Analysis of Docker instances installed under CentOS7.5". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.