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/03 Report--
Docker-Compose, an orchestration service of Docker, is a tool for defining and running complex applications on Docker, which allows users to deploy distributed applications in clusters.
Ockerfile allows users to manage a separate application container, while Compose allows users to define a set of associated application containers (called a project, that is, a project) in a template (YAML format), such as a Web service container plus a back-end database service container. **
Docker cpmose introduction:
Docker-compose: container orchestration tool. By having a .yaml or .yaml file, all container deployment methods, file mappings, container port mappings, etc., are written in a configuration file, and the docker-compose up command is executed just like a script to install and deploy the container one by one.
Docker Compose working schematic diagram:
There are two important concepts in Compose:
Service (service): a container for an application that can actually include several container instances running the same image. Project (project): a complete business unit consisting of a set of associated application containers, defined in the docker-compose.yml file
A project can be associated by multiple services (containers). Compose manages the project-oriented and easily manages the life cycle of a group of containers in the project through subcommands.
The Compose project is written by Python and the implementation invokes 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.
Docker Compose installation
1) download from the official website of github:
Download address: https://github.com/docker/compose/releases
Download to local:
[root@sqm-docker01 ~] # curl-L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname-s`-`uname-m`-o / usr/local/bin/docker-compose [root@sqm-docker01 ~] # chmod + x / usr/local/bin/docker-compose
After the download is successful, we can use docker-compose as an orchestration tool.
Before using docker-compose, we need to know which versions of docker are supported by each version of compose? When we download the compose command, the reference list is actually given below, as follows:
Check the version of docker that you deployed:
From the above review, you can see that my current docker version is 18.09, so basically all compose versions can be used because they are backward compatible, as long as they are higher than the docker version supported by the compose version.
Docker-compose application
First of all, in order to write a friendly and beautiful yaml file, you can set the distance of the tab key:
[root@sqm-docker01 ~] # vim .vimrc
[root@sqm-docker01 compose] # source / root/.vimrc # load to make it effective
One: simply deploy nginx services through docker-compose.yaml files
[root@sqm-docker01 compose] # vim docker-compose.yaml
/ / create a mount directory file: [root@sqm-docker01 compose] # mkdir webserver// use docker-compose up-d to start the service [root@sqm-docker01 compose] # docker-compose up-d in the background
/ / use docker-compose to view details: [root@sqm-docker01 compose] # docker-compose ps
/ / write a simple web page test file: [root@sqm-docker01 compose] # cd webserver/ [root@sqm-docker01 webserver] # echo "welcome to nginx" > index.html## visit web page: [root@sqm-docker01 webserver] # curl 127.0.0.1welcome to nginx
/ / use docker-compose stop to stop the service:
/ / if you are in another directory, you need to use the-f parameter to specify the path to run the service:
II: version upgrade of docker-compose+dockerfile deployment apache service
1) first create the mount directory and write the test file:
[root@sqm-docker01 ~] # mkdir-p httpd/html [root@sqm-docker01 ~] # cd httpd/html/ [root@sqm-docker01 html] # echo "hello welcome to httpd-v1.0" index.html [root@sqm-docker01 html] # echo "this is a testfile 1.0" > testfile.txt
2) write dockerfile
[root@sqm-docker01 html] # vim DockerfileFROM httpd:latestADD testfile.txt / root/ # Mount the files in the current directory to / root/ in the container
3) write the docker-compose.yaml file:
[root@sqm-docker01 html] # vim docker-compose.yaml
Version: "3" # version number services: # define service name (custom) httpd: build:. # to build dockerfile (. Represents the Dockerfile under the current directory) If dockerfie is defined, it means that you want to use the container name image: httpd:v1.0 # after running with custom image container_name: my_web # Image name: version number Note: if dockerfile is not defined, the image must be the correct image restart: always # keep running ports:-81:80 # Port number (host: in the container) volumes: # mount Mapping directory-/ root/httpd/html:/usr/local/apache2/htdocs
/ / run the docker-compose service:
[root@sqm-docker01 html] # docker-compose up-d
/ / check whether an image is generated:
Visit the web page:
/ / check whether the files in the / root/ directory in the container are imported successfully: [root@sqm-docker01 html] # docker exec my_web cat / root/testfile.txtthis is a testfile 1.0 for version upgrade:
# # modify the contents of the test file:
[root@sqm-docker01 html] # echo hello welcome to httpd-v2.0 > index.html [root@sqm-docker01 html] # echo this is a testfile 2.0 > testfile.txt
1) modify the docker-compose file:
[root@sqm-docker01 html] # vim docker-compose.yaml
Version: "3" services: httpd: build:. Container_name: my_web image: httpd:v2.0 # modify the image version to v2.0 restart: always ports:-81:80 volumes:-/ root/httpd/html:/usr/local/apache2/htdocs
/ / rebuild dockerfile:
/ / reload docker-compose to make it effective:
/ / check that the image has been upgraded to 2.0. I hope the version of the image will be retained.
/ / Test the contents of the visited web pages and files:
[root@sqm-docker01 html] # docker exec my_web cat / root/testfile.txtthis is a testfile 2.0
You can see that the version upgrade was successful, which is the benefit of docker-compose, but when you need to upgrade or other operations, you only need to rebuild the yaml file.
Note: after executing build, you must reload the docker-compose file, because build is just rebuilding dockerfile.
Third, deploy wordpress blog platform through docker-compose # # write .yaml file: [root@sqm-docker01 wordpress] # vim docker-compose.yamlversion: '3.1' # version is 3.1services: wordpress: image: wordpress # mirrored as wordpress restart: always volumes:-/ root/wordpress/mysql:/var/lib/mysql # to persist the data in the database Automatically mounts the directory in the container to the current directory ports:-8080wordpress WORDPRESS_DB_PASSWORD 80 # mapping port (host: container) environment: # defines variables with the same definition information as the following database information: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: 123.com WORDPRESS_DB_NAME: wordpress db: # defines the image of the mysql And the user name and password image: mysql:5.7 restart: always environment: MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: 123.com MYSQL_ROOT_PASSWORD: 123.com// run the yaml file: [root@sqm-docker01 wordpress] # docker-compose up-d
/ / check whether the container allows:
Log in to the web web page
Access address: http://172.16.1.30:8080/
Docker-compose commonly used command: # View the Compose template file used to specify the help docker-compose-hobby Musf. The default is docker-compose.yml, which can be specified multiple times. Docker-compose-f docker-compose.yml up-d # starts all containers, and-d will start and run all containers in the background. Docker-compose up-d # will disable and remove all containers and the output of network-related docker-compose down# view service containers docker-compose logs# lists all the current container docker-compose ps# built (rebuilt) service containers in the project. Once the service container is built, it will be marked with a tag name, such as web_db for a db container in the web project. You can run docker-compose build under the project directory at any time to rebuild the service docker-compose build# pull service dependent image docker-compose pull# restart project service docker-compose restart# to delete all (stopped state) service containers. It is recommended that you first execute the docker-compose stop command to stop the container. Docker-compose rm # executes a command on the specified service. The docker-compose run ubuntu ping docker.com# setting specifies the number of containers for the service to run. Set the number of docker-compose scale web=3 db=2# startup service containers that already exist through the parameters of service=num. Docker-compose start# stops the container that is already running, but does not delete it. These containers can be started again through docker-compose start. Docker-compose stop
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.