Timeline
Timeline
2025-10-14
init
This article introduces the basic knowledge and practical operations of Docker, covering common commands (image commands, container commands and parameters), container lifecycle management, the UnionFS layered loading principle of images, persistence and sharing of container data volumes, as well as the writing rules and build process of Dockerfile. The article also mentions installation considerations for common software such as MySQL and Redis, and emphasizes key issues such as the need for a foreground process when running a container in the background.
Common Docker Commands
Help and Startup Commands
1234567891011121314151617 | # Start Docker$ sudo systemctl start docker# Stop Docker$ sudo systemctl stop docker# Restart Docker$ sudo systemctl restart docker# Start on Boot$ sudo systemctl enable docker# View Docker Basic Information$ sudo docker info# Docker Command Help Documentation$ sudo docker 具体命令 --help |
Image Commands
123456 | # List Images on the Local Host$ docker images# List All Local Images (Including Intermediate Images)$ docker images -a# Show Only Image IDs$ docker images -q |
12345678 | # Search for an Image by Name$ docker search 镜像名# List Only N Images, Default 25$ docker search --limit N 镜像名# Pull an Image$ docker pull 镜像名# Pull an Image and Specify a Version (Tag)$ docker pull 镜像名[:TAG] |
12345678 | # View the Space Occupied by Images/Containers/Volumes$ docker system df# Delete a Single Image$ docker rmi 镜像名[:TAG]/镜像id# Delete Multiple Images, -f for Force Deletion$ docker rmi -f 镜像名1[:TAG] # Delete All Images$ docker rmi -f $(docker images -qa) |
Container Commands
12 | # Create and Start a Container$ docker run [OPTIONS] IMAGE [COMMAND] [ARG..] |
OPTIONS
- –name=“new container name” Specify a name for the container
- -d Run the container in the background and return the container ID, i.e., start a daemonized container
- -i Run the container in interactive mode, usually used together with -t
- -t Allocate a pseudo-TTY for the container, usually used together with -i: i.e., start an interactive container
- -P Random port mapping, uppercase P
- -p hostPort:containerPort Specify port mapping, lowercase p, e.g., -p 8080:80
12 | $ docker run -it ubuntu /bin/bash# Here we want an interactive shell, so we use /bin/bash |
12 | # List all running containers$ docker ps |
OPTIONS
- -a List all currently running containers + those that have run historically
- -l Show the most recently created container
- -n Show the last n created containers
- -q Quiet mode, only show container IDs
Exit the container
- Use run to enter the container, exit to leave,The container stops
1 | $ exit |
- Use run to enter the container, ctrl+p+q to exit**, the container does not stop**
Start a container that has stopped running*
1 | $ docker start 容器ID或者容器名 |
Stop a container
1 | $ docker stop 容器ID或容器名 |
Force stop a container
1 | $ docker kill 容器ID或容器名 |
Delete a stopped container
1 | $ docker rm 容器ID或容器名 |
To delete a container that is not stopped, you need to add the -f parameter
Delete multiple container instances at once danger!
123 | $ docker rm -f $(docker ps -a -q)# or$ docker ps -a -q | xargs docker rm |
Some important questions
Start a daemonized container
1 | $ docker run -d ubuntu |
Question: Then use docker ps -a to check and find that the container has exited, the reason is
**For a Docker container to run in the background, there must be a foreground process.**If the command run by the container is not one of those long-running commands, it will exit automatically.
Therefore, for some images, the -d parameter does not work; you need to use -it to run an interactive container.
12 | $ docker run -it redis:6.0.8$ docker run -d redis:6.0.8 |
View the logs of a container.
1 | $ docker logs 容器ID |
View the processes running inside a container.
1 | $ docker top 容器ID |
View the internal details of a container.
1 | $ docker inspect 容器id |
Enter a running container and interact with it via the command line.
1234 | # Enter a running container and interact with it via the command line.$ docker exec -it 容器ID /bin/bash# Re-enter.$ docker attach 容器ID |
Difference.
- attach directly enters the terminal of the container’s startup command and does not start a new process. Exiting with exit will directly cause the container to stop.
- exec opens a new terminal in the container and starts a new process. Exiting with exit will not cause the container to stop.
Therefore, in general, we first use docker run -d and then use docker exec -it.
Copy files from a container to the host.
123 | $ docker cp 容器ID:容器内路径 目的主机路径# example$ docker cp ddd1abihiin87:/tmp/a.txt ~/Desktop |
Import and export containers.
123456 | # export exports the container's content stream as a tar archive file.$ docker export 容器ID > abc.tar# import creates a new file system from the contents of the tar package and then imports it as an image.$ cat abc.tar | docker import - 镜像用户/镜像名:镜像版本号# example$ cat abc.tar | docker import - atguigu/ubuntu3.7 |
Docker image.
What is an image?
Docker images are actually composed of a layer-by-layer file system. This layered file system is UnionFS.
UnionFS (Union File System)
Union File System (UnionFS) is a layered, lightweight, and high-performance file system. It supports modifications to the file system being overlaid layer by layer as a single commit. It can also mount different directories to the same virtual file system (unite several directories into a single virtual filesystem). UnionFS is the foundation of Docker images. Images can be inherited through layering. Based on a base image (which has no parent image), various specific application images can be created.
Docker image loading principle.
- bootfs (boot file system) mainly contains the bootloader and kernel.
The bootloader is mainly for loading the kernel. When Linux first starts, it loads the bootfs file system. At the bottom layer of a Docker image is the boot file system bootfs. This layer is the same as our typical Linux/Unix file system, containing the boot loader and kernel. When the boot loading is complete, the entire kernel is in memory. At this point, the right to use memory has been transferred from bootfs to the kernel, and the system will also unmount bootfs. - rootfs(root file system)
On top of bootfs. It contains the standard directories and files of a typical Linux system, such as /dev, /proc, /bin, /etc. rootfs is the distribution of various different operating systems, such as Ubuntu, CentOS, etc.
For a minimal OS, rootfs can be very small, only needing to include the most basic commands, tools, and program libraries, because the underlying host kernel is used directly, and you only need to provide rootfs yourself. It can be seen that for different Linux distributions, bootfs is basically the same, while rootfs differs, so different distributions can share bootfs.
One of the biggest advantages of image layering is resource sharing, making it easy to copy and migrate, and it is for reuse.
For example, if multiple images are built from the same base image, then the Docker Host only needs to save one copy of the base image on disk, and also only needs to load one copy of the base image in memory, to serve all containers. Moreover, every layer of an image can be shared.
Key understanding
Docker image layers are all read-only, and the container layer is writable.
When a container starts, a new writable layer is loaded on top of the image. This layer is usually called the ‘container layer’, and everything below the container layer is called the image layer.
Publishing images
docker commit commits a container copy to make it a new image.
123 | $ docker commit -m="提交的描述信息" -a="作者" 容器ID 要创建的目标镜像名:[标签名]# example$ docker commit -m="vim add ok" -a="zhaohang" fcbfaingngi5 hnu/myubuntu:1.3 |
Afterwards, you can publish the image to Docker Hub or Alibaba Cloud (public registry), or publish it to a private registry (equivalent to the relationship between GitLab and GitHub).
Docker container data volumes
When docker mounts a host directory, if you encounter ‘cannot open directory: Permission denied’, you just need to add an extra --privileged=true parameter after the mounted directory.
With this parameter, root inside the container has true root privileges; otherwise, root inside the container only has the permissions of an ordinary user on the host.
123 | $ docker run -it --privileged=true -v /宿主机绝对路径目录:/容器内目录 镜像名/镜像ID# example$ docker run -d -p 5000:5000 -v /zzyyuse/myregistry/:/tmp/registry --privileged=true registry |
By default, the registry is created in the /var/lib/registry directory inside the container. It is recommended to use container volume mapping yourself to facilitate joint debugging with the host machine.
A volume is a directory or file that exists in one or more containers, mounted to the container by Docker, but does not belong to the Union File System, so it can bypass the Union File System to provide some features for users to persistently store or share data.
The design purpose of volumes isdata persistence, completely independent of the container’s lifecycle, so Docker will not delete the mounted data volume when the container is deleted.
Note: Changes to container volumes will not be included in image updates. The lifecycle of a data volume lasts until no container uses it.
Some examples
1 | $ docker run -it --privileged=true -v /tmp/host_data:/tmp/docker_data --name=u1 ubuntu |
Read/Write Rule Mapping and Additional Notes
Read-only permission: the container instance is restricted internally, can only read but not write.
1 | $ docker run -it --privileged=true -v 宿主机绝对路径目录:容器内目录:ro 镜像名 |
Volume inheritance and sharing
12 | $ docker run -it --privileged=true --volumes-from u1 --name u2 ubuntu$ docker run -it --privileged=true --volumes-from=u1 --name=u2 ubuntu |
If the source container of volumes-from is gone, the target container still mounts the source container’s volume.
Introduction to Docker Standard Installation
Pulling some software with Docker may cause some issues, such as MySQL character set configuration.
mysql
12345 | $ docker pull mysql:8.0.20$ docker run -d -p 3306:3306 --privileged=true -v /root/mysql/log:/var/log/mysql -v /root/mysql/data:/var/lib/mysql -v /root/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 --name mysql mysql:8.0.20$ cd /root/mysql/conf$ touch my.cnf$ vim my.cnf |
MySQL configuration (it seems that versions above 8.0 don’t need configuration).
12345 | [client]default_character_set=utf8[mysqld]collation_server = utf8_general_cicharacter_set_server = utf8 |
1234 | $ docker restart mysql$ docker exec -it mysql /bin/bash$ mysql -uroot -p$ SHOW VARIABLES LIKE 'character%' |
Data persistence after mounting volumes.
Redis cluster configuration, scaling out, scaling in, etc.
Redis has not been systematically studied yet.
…
Dockerfile Parsing
What is a Dockerfile?
A Dockerfile is a text file used to build Docker images. It is a script composed of instructions and parameters needed to build the image.
Dockerfile Content Basics
- Each reserved word instruction must be in uppercase letters and followed by at least one parameter.
- Instructions are executed in order from top to bottom.
indicates a comment.
- Each instruction creates a new image layer and commits the image.
The general process of Docker executing a Dockerfile.
- Docker runs a container from the base image.
- Executes an instruction and makes modifications to the container.
- Performs an operation similar to docker commit to commit a new image layer.
- Docker then runs a new container based on the just-committed image.
- Executes the next instruction in the Dockerfile until all instructions are completed.
Dockerfile reserved words.
FROM
Base image: which image the current image is based on. Specify an existing image as a template. The first instruction must be FROM.
MAINTAINER
The name and email address of the image maintainer.
RUN
The command that needs to be run when the container is built.
Two formats: shell format and exec format.
RUN is executed during docker build.
EXPOSE
The port currently exposed by the container to the outside
WORKDIR
Specifies the working directory that the terminal defaults to after the container is created, a landing point
USER
Specifies which user the image runs as; if none is specified, the default is root
ENV
Used to set environment variables during the image build process
ADD
Copies files from the host directory into the image and automatically handles URLs and extracts tar archives
COPY
Similar to ADD, copies files and directories into the image. It copies files/directories from the
COPY src dest
COPY [“src”,“dest”]
VOLUME
Container data volume, used for data storage and persistence
The difference between VOLUME and run -v, and when VOLUME needs to be used
When the container is running, you should try to keep the container storage layer from being written to. For applications such as databases that need to save dynamic data, their database files should be stored in a volume. To prevent users from forgetting to mount the directory where dynamic files are saved as a volume at runtime, we can specify in the Dockerfile in advance that certain directories be mounted as anonymous volumes. In this way, if the user does not specify a mount at runtime, the application can still run normally and will not write a large amount of data to the container storage layer.
So in actual use, is the VOLUME instruction in the Dockerfile just like the -v parameter in docker run, binding a host directory to a directory in the container to achieve directory sharing?
Not exactly, actuallyThe VOLUME instruction only declares a directory in the container as an anonymous volume, but it does not have the function of binding the anonymous volume to a specified directory on the host。
When we declare an anonymous volume with VOLUME in the Dockerfile used to build the image, and we run a container from this image, Docker will create a directory under a specified directory in its installation directory to bind to the container’s anonymous volume (this specified directory may vary with different Docker versions). My current directory is: /var/lib/docker/volumes/{container ID}.
SummaryVOLUME only specifies a directory so that even if the user forgets to specify the -v parameter when starting, the container can still run normally. For example, with MySQL, you can’t say that if the user doesn’t specify -v at startup and then deletes the container, all MySQL data files are deleted. That would cause a major accident in production. Therefore, MySQL’s Dockerfile needs to configure VOLUME, so that even if the user does not specify -v, the data files will not be lost after the container is deleted. They can still be recovered.
Will the data files in the location specified by VOLUME be deleted after the container is deleted?
VOLUME, like the -v instruction, does not delete files mapped on the host after the container is deleted.
What happens if -v and VOLUME specify different locations?
The directory set by -v will prevail. In fact, the purpose of the VOLUME instruction is to avoid data loss when the user forgets to specify -v. So if the user specifies -v, the location specified by VOLUME is naturally not needed.
In fact, for a typical Dockerfile, unless it is an application like a database that needs to persist data to disk, there is no need to specify VOLUME. Specifying VOLUME is only to avoid the situation where, if the user forgets to specify -v, all data stays in the container, and once the container is deleted, all data is lost.
**Then why doesn’t the Dockerfile provide an instruction that can map a host directory:container directory like that?**Actually, this design makes sense. If a host directory were specified in the Dockerfile, the Dockerfile would no longer be portable. After all, the directory each person needs to map may be different. The best approach is to leave this right to each person who runs the Dockerfile, which is why there is the instruction run -v host directory:container directory.
1234 | $ docker volume create edc-nginx-vol // Create a custom container volume$ docker volume ls // View all container volumes$ docker volume inspect edc-nginx-vol // View details of a specified container volume$ docker volume rm edc-nginx-vol // Delete a custom data volume |
docker volume command
https://blog.csdn.net/lihongbao80/article/details/122812274
VOLUME
CMD
- Specify what to do after the container starts
Similar to RUN, it also has two formats: shell and exec - There can be multiple CMD instructions in a Dockerfile, but only the last one takes effect. CMD will be replaced by the parameters after docker run
Example:
In Tomcat’s Dockerfile:
12 | EXPOSE 8080CMD ["catalina.sh","run"] |
If we start tomcat like this:
1 | $ docker run -it -p 8080:8080 57800e5b1cbf /bin/bash |
The /bin/bash parameter will override the CMD parameter, causing tomcat to not start properly
- Difference from RUN
- RUN is a command executed during docker build when building the image
- CMD is a command executed when starting a container with docker run
ENTRYPOINT
It is also used to specify a command to run when a container starts, similar to the CMD command, butENTRYPOINTIt will not be overridden by the command after docker run, and these command-line arguments will be passed as parameters toENTRYPOINTthe program of the instruction
1234 | FROM nginxENTRYPOINT ["nginx","-c"] # Fixed parametersCMD ["/etc/nginx/nginx.conf"] # Variable parameters |
Execute according to the Dockerfile
123 | $ docker run nginx:test# The command actually derived$ nginx -c /etc/nginx/nginx.conf |
Run by actively passing parameters
123 | $ docker run nginx:test -c /etc/nginx/new.conf# Actually derived command$ nginx -c /etc/nginx/new.conf |
Case
Custom image centosjava8
Requirement: Centos7 image with vim + ifconfig + jdk8
123456789101112131415161718192021222324 | FROM centosMAINTAINER even629<asqwgo@163.com>ENV MYPATH /usr/localWORKDIR $MYPATH# Install vim editorRUN yum -y install vim# Install ifconfig command to view network IPRUN yum -y install net-tools# Install java8 and lib libraryRUN yum -y install glibc.i686RUN mkdir /usr/local/java# ADD is a relative path. Add jdk-8u171-linux-x64.tar.gz to the container. The installation package must be in the same location as the Dockerfile, and it will automatically extract.ADD jdk-8u171-linux-x64.tar.gz /usr/local/java/# Configure Java environment variablesENV JAVA_HOME /usr/local/java/jdk1.8.0_171ENV JRE_HOME $JAVA_HOME/jreENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATHENV PATH $JAVA_HOME/bin:$PATHEXPOSE 80CMD echo $MYPATHCMD echo "success-----------ok"CMD /bin/bash |
- Build
1 | $ docker build -t 新镜像名字:TAG . |
(Note there is a dot at the end.)
Dangling image
- What is it
Images whose repository name and tag are both <none>, possibly caused by Dockerfile writing issues or problems during the Docker build. - View all dangling images
1 | $ docker image ls -f dangling=true |
- Delete dangling images
1 | $ docker image prune |
Docker Microservices in Action
- Create a regular microservice module through IDEA
- Publish the microservice via Dockerfile and deploy it to a Docker container
1234567891011 | FROM java:8MAINTAINER even629<asqwgo@163.com># VOLUME specifies the temporary file directory as /tmp. It creates a temporary file under the host's /var/lib/docker directory and links it to the container's /tmp.VOLUME /tmp# Add the jar package to the container and rename it to zzyy_docker.jarADD docker_boot-0.0.1-SNAPSHOT.jar zzyy_docker.jar# Run the jar packageRUN bash -c 'touch /zzyy_docker.jar'ENTRYPOINT ["java","-jar","/zzyy_docker.jar"]#Expose port 6001 as the microserviceEXPOSE 6001 |
1 | $ docker build -t zzyy_docker:1.6 . |
Docker network
After Docker starts, a virtual bridge named docker0 is created
12345678 | # View all Docker networks$ docker network ls# Create a network$ docker network create aa_network# Delete a network$ docker network rm aa_network# View network source data$ docker network inspect bridge |
The 3 major network modes created by Docker by default:
- bridge
- host
- none
Docker’s 5 major network modes:
- bridge
Allocate and set IP, etc. for each container, and connect the container to a docker0
Virtual bridge, which is the default mode
Use --network bridge to specify, docker0 is used by default. - host
The container will not virtualize its own network card or configure its own IP, etc., but will use the host’s IP and port.
Specify with --network host. - none
The container has an independent Network namespace, but no network settings are applied to it, such as assigning veth pairs, bridge connections, IP, etc.
Specify with --network none. - container
The newly created container will not create its own network card or configure its own IP, but shares the IP and port range with a specified container.
Use --network container:NAME or container ID. - …
What can Docker networks do:
- Interconnection and communication between containers, as well as port mapping.
- When container IPs change, they can communicate directly via service names without being affected.
The bridge docker0 creates a pair of peer virtual device interfaces, one called veth and the other eth0, matched as a pair.
In host mode, the same network segment as the host is used.
1234 | # Warning$ docker run -d -p 8083:8080 --network host --name tomcat83 billygoo/tomcat8-jdk8# Correct.$ docker run -d --network host --name tomcat83 billygoo/tomcat8-jdk8 |
If host mode is used, port numbers are based on the host’s port numbers, and increment when duplicated.
none mode:
In this mode, no network configuration is performed for the Docker container.
That is to say, this Docker container has no network card, IP, routing, or other information, only a lo.
We need to add a network card, configure IP, etc. for the Docker container ourselves.
container mode
123 | $ docker run -d -p 8085:8080 --name tomcat85 billygoo/tomcat8-jdk8# Running the following command will cause an error.$ docker run -d -p 8086:8080 --network container:tomcat85 --name tomcat86 billygoo/tomcat8-jdk8 |
It is equivalent to tomcat86 and tomcat85 sharing the same IP and the same port, causing a port conflict, because Tomcat needs port 8080, so container mode is not suitable in this case.
1234 | $ docker run -it --name=alpine1 alpine /bin/sh$ docker run -it --network container:alpine1 --name=alpine2 alpine /bin/sh# Enter the container and view the network.$ ip addr |
If alpine1 is shut down, alpine2’s network will be gone.
Custom network example.
- Custom bridge network. Custom networks use the bridge network by default.
1 | $ docker network create zzyy_network |
- Create a custom network
12345678910 | $ docker run -d -p 8081:8080 --network zzyy_network --name tomcat81 billygoo/tomcat8-jdk$ docker run -d -p 8082:8080 --network zzyy_network --name tomcat82 billygoo/tomcat8-jdk$ docker exec -it tomcat81 bash$ ip addr$ ping tomcat82$ exit$ docker exec -it tomcat82 bash$ ip addr$ ping tomcat81$ exit |
- Create a container and add it to the custom network created in the previous step
- Ping each other to test connectivity
docker-compose
Compose is a tool from Docker that manages multiple Docker containers as one application. You need to define a configuration file in YAML format.docker-compose.ymlWrite the call relationships between multiple containers. Then, with just one command, you can start/stop these containers simultaneously.
Compose core concepts
- One file
docker-compose.yml
- Two elements
- Service
Individual application container instances, such as order microservice, inventory microservice, MySQL container, Nginx container, or Redis container.
- Project
A complete business unit composed of a group of related application containers, defined in the docker-compose.yml file.
3 steps to use Compose
- Write a Dockerfile to define each microservice application and build the corresponding image files.
- Use docker-compose.yml to define a complete business unit and arrange the container services in the overall application.
- Finally, run the docker-compose up command to start and run the entire application, completing one-click deployment and go-live.
Common Compose commands
12345678910111213 | $ docker-compose -h #View help$ docker-compose up #Start all docker-compose services$ docker-compose up -d #Start all docker-compose services and run in the background$ docker-compose down #Stop and remove containers, networks, volumes, and images$ docker-compose exec yml里面的服务id # Enter the container instance: docker-compose exec <service id in docker-compose.yml> /bin/bash$ docker-compose ps #Display all running containers orchestrated by the current docker-compose$ docker-compose top #Display container processes orchestrated by the current docker-compose$ docker-compose logs yml里面的服务id #View container output logs$ docker-compose config #Check configuration$ docker-compose config -q #Check configuration; output only if there are problems$ docker-compose restart #Restart service$ docker-compose start #Start service$ docker-compose stop #Stop service |
Orchestrate microservices with Compose
- Write docker-compose.yml
container_name sets the container name
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 | version: "3"services: microService: image: zzyy_docker:1.6 container_name: ms01 ports: - "6001:6001" volumes: - /app/microService:/data networks: - atguigu_net depends_on: - redis - mysql redis: image: redis:6.0.8 ports: - "6379:6379" volumes: - /app/redis/redis.conf:/etc/redis/redis.conf - /app/redis/data:/data networks: - atguigu_net command: redis-server /etc/redis/redis.conf mysql: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: '123456' MYSQL_ALLOW_EMPTY_PASSWORD: 'no' MYSQL_DATABASE: 'db2021' MYSQL_USER: 'zzyy' MYSQL_PASSWORD: 'zzyy123' ports: - "3306:3306" volumes: - /app/mysql/db:/var/lib/mysql - /app/mysql/conf/my.cnf:/etc/mysql/conf.d/my.cnf - /app/mysql/init:/docker-entrypoint-initdb.d networks: - atguigu_net command: --default-authentication-plugin=mysql_native_password #Resolve external access issuesnetworks: atguigu_net: |
- Change the hardcoded IP in application.yml to the Docker service name
For example:
123 | spring: datasource: url: jdbc:mysql://mysql:3306/db2021?useUnicode=true&characterEncoding=utf-8&useSSL=false |
- Write a Dockerfile and place the packaged jar in the same directory as the Dockerfile
1 | $ docker build -t zzyy_docker:1.6 . |
- Use docker-compose
1234 | # Check the syntax of the yaml file$ docker-compose config -q# Execute, -d means run in the background$ docker-compose up -d |
After running, check the network
1 | $ docker network ls |
Found that the network name has a prefix and suffix, and the service name also has a prefix and suffix
Docker lightweight visualization tool Portainer
https://www.portainer.io/
Docker container monitoring with CAdvisor+InfluxDB+Grafana (CIG)
Native commands
1 | $ docker stats |
It is very convenient to see data such as CPU, memory, and network traffic of all containers on the current host, but the docker stats results can only cover all containers on the current host, the data is real-time, there is no place to store it, and there is no health indicator threshold warning function.
CAdvisor for monitoring and collection + InfluxDB for data storage + Grafana for chart display
- CAdvisor
CAdvisor is a container resource monitoring tool, including monitoring of container memory, CPU, network I/O, disk I/O, etc., and also provides a web page to view the real-time running status of containers. CAdvisor stores data for 2 minutes by default, and it is only for a single physical machine. However, CAdvisor provides many data integration interfaces, supporting integration with InfluxDB, Redis, Kafka, etc. You can add corresponding configurations to send monitoring data to these databases for storage.
CAdvisor has two main functions:
- Display monitoring data at two levels: Host and container
- Display historical change data
- InfluxDB
InfluxDB is an open-source distributed time-series, event, and metrics database written in Go, requiring no external dependencies. CAdvisor itself already provides an integration method for InfluxDB; just specify the configuration when starting the container.
Main features of InfluxDB:
- Based on time series, supports functions related to events (such as max, min, sum, etc.)
- Measurability: You can compute on large amounts of data in real time.
- Event-based: It supports arbitrary event data.
- Grafana
Grafana is an open-source data analysis and visualization platform that supports multiple data source configurations (supported data sources include InfluxDB, MySQL, Elasticsearch, OpenTSDB, Graphite, etc.) and rich plugin and template features, supporting chart permission control and alerts.
Main features of Grafana:
- Flexible and rich graphical options
- Can mix multiple styles
- Supports day and night modes
- Multiple data sources
Three-piece container orchestration
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 | version: '3.1' volumes: grafana_data: {} services: influxdb: image: tutum/influxdb:0.9 restart: always environment: - PRE_CREATE_DB=cadvisor ports: - "8083:8083" - "8086:8086" volumes: - ./data/influxdb:/data cadvisor: image: google/cadvisor links: - influxdb:influxsrv command: -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxsrv:8086 restart: always ports: - "8080:8080" volumes: - /:/rootfs:ro - /var/run:/var/run:rw - /sys:/sys:ro - /var/lib/docker/:/var/lib/docker:ro grafana: user: "104" image: grafana/grafana user: "104" restart: always links: - influxdb:influxsrv ports: - "3000:3000" volumes: - grafana_data:/var/lib/grafana environment: - HTTP_USER=admin - HTTP_PASS=admin - INFLUXDB_HOST=influxsrv - INFLUXDB_PORT=8086 - INFLUXDB_NAME=cadvisor - INFLUXDB_USER=root - INFLUXDB_PASS=root |
