In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "the deployment and basic use of Docker Compose". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the method of Docker Compose deployment and basic use".
An overview of docker compose
Compose is a tool for defining and running multi-container docker applications. With compose, you can use yaml files to configure your application's services. Then, using a single command, you can create and start all services from the configuration.
Compose works in all environments: production, staging, development, testing, and ci workflows.
Using compose is basically a three-step process:
Define your application environment in dockerfile so that it can be reproduced anywhere.
Define the services that make up the application, docker-compose.yml so that they can run together in an isolated environment.
Run docker-compose up and compose start and run the entire application.
An example of docker-compose.yml format is as follows:
Version: '3'services: web: build: .ports:-"5000 build" volumes: -.: / code-logvolume01:/var/log links:-redis redis: image: redisvolumes: logvolume01: {}
Compose has commands to manage the entire lifecycle of the application:
Start, stop and rebuild services
View the status of running services
Log output of streaming running service
Run an one-time command on the service
Two docker compose installation
2.1 binary download and installation
Root@docker01:~# sudo curl-l "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname-s)-$(uname-m)"-o / usr/local/bin/docker-composeroot@docker01:~# sudo chmod + x / usr/local/bin/docker-compose
2.2 pip installation (recommended)
Root@docker01:~# apt-get-y install pythonroot@docker01:~# curl https://bootstrap.pypa.io/get-pip.py-o get-pip.pyroot@docker01:~# python get-pip.py # install piproot@docker01:~# pip install docker-compose # install docker compose root@docker01:~# docker-compose version # verify installation
Three docker compose examples
3.1 build the application
Root@docker01:~# mkdir composetest# creates a docker compose directory root@docker01:~# cd composetest/root@docker01:~/composetest# vi app.py
Tip: use python to build a simple application. For more information, please refer to the official example.
3.2Create dockerfile
Root@docker01:~/composetest# vi dockerfile # use dockerfile to build image from python:3.4-alpinerun mkdir / root/.pip # create pip source configuration directory add pip.conf / root/.pip/pip.conf # add domestic piping source to the image to be built add. / codeworkdir / coderun pip install-r requirements.txt # install cmd using pip according to the file list ["python", "app.py"]
Note: the above dockerfile related commands refer to "004.docker Image Management".
Root@docker01:~/composetest# vi requirements.txt # create installation software list file flaskredisroot@docker01:~/composetest# vi pip.conf # create a file based on domestic piping source [global] index-url = https://mirrors.aliyun.com/pypi/simple/[install]trusted-host=mirrors.aliyun.com
Dockerfile explained:
Start building the image from the python 3.4 image.
Create a pip configuration directory.
Add the national piping source configuration file to the path in the / root/.pip/ image.
Add the current directory. To the path in the / code image.
Set the working directory to / code.
Install python related packages.
Set the default command for the container to python app.py.
3.3Building services using docker compose
Root@docker01:~/composetest# vi docker-compose.ymlversion: '3'services: web: build: .ports:-"5000 build 5000" redis: image: "redis:alpine"
Docker compose explained:
This compose file defines two services, web and redis.
Web Service:
Use images built from the current directory of dockerfile.
Forward public port 5000 on the container to port 5000 on the host. Even use the default port 5000 of the flask web server.
Redis Service:
Use the public redis image pulled from docker hub.
Root@docker01:~/composetest# docker-compose up-d # starts building
Four verification confirmation
Browser access:
Root@docker01:~/composetest# docker-compose psroot@docker01:~/composetest# docker ps
Root@docker01:~/composetest# docker image ls
Tip:
The container name rule built using docker compose is: [directory where the build is located] _ [yml build file definition service name] _ [container startup serial number].
The rule for the name of an image built using docker compose is: [directory where it is built] _ [yml build file definition service name], and its tag is latest.
Fifth, mount volume construction
Root@docker01:~/composetest# vi docker-compose.ymlversion: '3'services: web: build: .ports:-"5000 return 5000" volumes: -.: / code redis: image: "redis:alpine" root@docker01:~/composetest# docker-compose up-d # build root@docker01:~/composetest# vi app.py again... return' hello docker! i have been seen {} times.\ n'.format (count).
Browser access:
Tip: after mounting the local volume to the container, you can quickly modify the local file, so as to dynamically modify the container without rebuilding the image.
Six docker compose other commonly used commands
Docker-compose up-d: run the service in the background; docker-compose ps: view the currently running container; docker-compose run: run an one-time command, such as docker-compose run web env.
Docker-compose stop: stop services, such as docker-compose stop web
Tip: docker-compose takes the service name in yaml as a parameter, not the container name or id.
Docker-compose down-- volumes: completely delete the container and delete the data volumes used by the container.
At this point, I believe you have a deeper understanding of "Docker Compose deployment and basic use methods". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.