In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Introduction to Docker-Compose
Docker-Compose project is the official open source project of Docker, which is responsible for the rapid orchestration of Docker container cluster and provides scale (service expansion) function.
Docker-Compose divides the managed containers into three layers, namely, project, service and container. All the files under the Docker-Compose running directory (docker-compose.yml,extends files or environment variable files, etc.) form a project, which is the current directory name if no special project name is specified. A project can contain multiple services, and each service defines the images, parameters, and dependencies of the container. A service can include multiple container instances. Docker-Compose does not solve the problem of load balancing, so you need to use other tools to achieve service discovery and load balancing.
The project configuration file of Docker-Compose defaults to docker-compose.yml and can be customized through the environment variable COMPOSE_FILE or-f parameter, which defines multiple dependent services and the container in which each service runs.
Using a Dockerfile template file, you can easily define a separate application container. In the work, we often encounter the situation that multiple containers need to cooperate with each other to complete a task. For example, in order to implement a Web project, in addition to the Web service container itself, it is often necessary to add a back-end database service container and even a load balancing container.
Compose allows users to define a set of associated application containers as a project (project) through a separate docker-compose.yml template file (YAML format).
The Docker-Compose project is written by Python and calls the API provided by the Docker service to manage the container. Therefore, as long as the operating platform supports Docker API, Compose can be used for orchestration management on it.
Suppose you have a java image, a mysql image, and a nginx image. If there is no docker-compose, then every time you start, you need to type the startup parameters of each container, environment variables, container naming, specify different container link parameters, and a series of operations, which is quite tedious. After using docker-composer, you can write these commands in the docker-composer.yml file at one time, and then every time you start the entire environment (including 3 containers), you only need to ok by typing a docker-composer up command.
First of all, briefly understand the process of using docker, which is divided into image building and container startup.
Image build: create an image that contains the environment, program code, and so on, required for installation and operation. This creation process is done using dockerfile.
Container startup: the container finally starts the service by pulling the built image and starting the service through a series of running instructions (such as port mapping, external data mount, environment variables, etc.). For a single container, this can be run through docker run.
If the operation of multiple containers (such as service orchestration) can be implemented through docker-compose, it can easily run multiple containers as service (or just one of them, of course), and provides scale (service expansion) function.
A brief summary:
Dockerfile: building an image
Docker run: launch the container
Docker-compose: start the service
Installation
Recommend official installation
Curl-L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname-s)-$(uname-m)"-o / usr/local/bin/docker-compose
Chmod + x / usr/local/bin/docker-compose
[root@rancher] # docker-compose-v
Docker-compose version 1.24.1, build 4667896b
Unloading
If it is installed in a binary package, delete the binaries:
Sudo rm / usr/local/bin/docker-compose
If installed through the Python pip tool, remove it by executing the following command:
Sudo pip uninstall docker-compose
Common command
-Compose FILE specifies the template file of docker-compose.yml, which can be specified multiple times.
-p, specify the project directory of docker-compose, that is, the directory where docker-compose.yml files are stored
-vmaine copyright version prints and exits
Docker-compose ps displays all containers
Docker-compose up-d nginx builds and starts the nginx container in the background without adding nginx to start all services. The following is equivalent.
Docker-compose run allows you to run one-time commands for your application
Docker-compose start nginx starts the nginx container
Docker-compose restart nginx restart the nginx container (note the service in the orchestration file)
Docker-compose stop nginx stop nginx Container
Docker-compose pause nginx pauses the nginx container
Docker-compose unpause nginx recovery nginx Container
Docker-compose kill nginx Force stop nginx Container
Docker-compose rm nginx deletes the nginx container (the container must be closed before deletion)
Docker-compose exec nginx bash logs in to the nginx container
Docker-compose down-v stops and deletes containers, networks, images, and volumes, and-v (--volumes) deletes container volumes
Docker-compose logs-f-- tail 50 nginx looks at nginx's real-time log and only looks at the last 50 lines.
Docker-compose events-json nginx outputs nginx's docker log in the form of json
Docker-compose config-Q verification (docker-compose.yml) file configuration, when the configuration is correct, do not output anything, when the file configuration error, output error information.
Docker-compose build nginx builds an image
Docker-compose build-no-cache nginx builds without caching.
Docker-compose scale sets the number of containers for the service
Docker-compose pull pulls the service image
Docker-compose push push service image
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.