Docker-Compose basics and introduction

Source: Internet
Author: User
Tags define function docker compose docker swarm docker machine
Introduction: docker compose is a standalone container orchestration tool officially launched by docker. It is also known as docker swarm and docker machine, and is called docker container orchestration sanqike. Although it is cracked by k8s, however, because it is easy to learn, it still occupies a considerable position in Small and Medium-sized clusters to use compose: 1. Define your application environment, dockerfile allows replication anywhere. 2. Define the services that constitute the application, docker-compose.yml so that they can run in an isolated environment 3. Features of running docker-Compose up and compose starts running the entire application compose: 1. Multiple environments on a single host are isolated. 2. Volume Data is retained when a container is created. 3. Only modified containers are re-created. 4. Variables and move and merge between environments for installation: docker compose depends on all the work on docker. Before compose, make sure that you have installed docker binary installation on the local or remote host: curl-L "plugin (uname-S)-$ (uname-m) "-O/usr/local/bin/docker-Compose chmod + x/usr/local/bin/docker-Compose Pip installation: Pip install docker-compose a simple example: mkdir composetest & CD composetest # create a dedicated directory for writing and saving the compose file cat app. PY # compile a flask web application as the test import time import redis from flask impo RT flask APP = flask (_ name _) cache = redis. redis (host = 'redis ', Port = 6379) # connect to redis # define function def get_hit_count (): retries = 5 While true: Try: Return cache. incr ('hits ') Doesn't redis. exceptions. connectionerror as exc: If retries = 0: Raise exc retries-= 1 time. sleep (0.5) @ app. route ('/') def Hello (): Count = get_hit_count () # Add 1 return 'Hello world! I have been seen {} Times. \ n '. format (count) If _ name _ = "_ main _": # Run the web application. run (host = "0.0.0.0", DEBUG = true) Cat dockerfile # compile the docker file so that compose can dynamically build an image based on the docker file from Python: 3.4-Alpine add. /code workdir/code run Pip install flask redis cmd ["Python", "app. PY "] cat docker-compose.yml # compile the compose file to define the relationship between containers version: '3' services: Web: Build :. ports:-"5000: 5000" volumes :-. :/code redis: Image: "redis: Alpine" docker-Compose up # Start the docker cluster curl http: // 127.0.0.1 defined by docker compose: 5000/# access the web app # sample source # https://docs.docker.com/compose/gettingstarted/#step-5-edit-the-compose-file-to-add-a-bind-mount docker-Compose command: Introduction: 1, docker-Compose command execution must be specified or there is a compose file in the current directory, and the output content is the compose. the yml file defines the information in the cluster. 2. Each cluster can have multiple services. yml Services Definition option:-F specifies the compose file path (multiple sub-commands can be specified): Create to create a compose cluster, but not start (obsolete, use up -- no-start instead) down to stop or delete containers, networks, image and data volume exec run commands in the container or connect to the container help view help information images List the image used by the compose cluster kill compose cluster logs get compose cluster log pause compose cluster PS list is the running container pull pulls compose. all docker images defined in the yml file are pushed to upload compose. all docker images defined in the yml file restart compose cluster RM delete a stopped container or compose cluster run and exec change the number of copies of specified services in the compose cluster in the same scale start compose Cluster stop stop compose cluster top show the processes running in the compose cluster and their statuses unpause resume paused compose cluster up create and start a compose cluster version output compose version

Docker-Compose basics and introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.