The login
registered
Write an article
Home page
Download the APP
Basic usage of Docker-compose
Webug community
Basic usage of Docker-compose
This article was first published on my blog: Address
Introduction to the
Compose is a Docker application that is user-defined and runs multiple containers. In Compose you can use YAML files to configure your application services. You can then create and start all of your configured services with a simple command.
Compose is composed in three steps:
- Define your application environment in Dockfile so that it can be copied anywhere.
- Define the services that make up the application in docker-comemage.yml so that they can run together in an isolated environment.
- Finally, run dcoker-compose up, and Compose will start and run the entire application.
Install the docker – Compose
There are two main installation methods, and I used the first one.
The first kind of
Download the latest docker-compose file
The curl -l https://github.com/docker/compose/releases/download/1.16.1/docker-compose- ` ` uname - s - ` uname -m ` - o /usr/local/bin/docker-composeCopy the code
The /usr/local/bin/docker-compose directory must be authorized after the download is complete
chmod +x /usr/local/bin/docker-compose
Copy the code
The test results
Docker-compose --version Outputs docker-compose version 1.16.1, build 6d1AC21Copy the code
The second,
Install using PIP
pip install docker-compose
Copy the code
The prerequisite is that your server already has the PIP component installed
uninstall
The first kind of
rm /usr/local/bin/docker-compose
Copy the code
The second,
pip uninstall docker-compose
Copy the code
use
Let’s take Kafka as an example
Wurstmeister/Zookeeper restart: Ports: - "2181:2181" # container name container_name: zookeeper kafka1: Wurstmeister/Kafka volumes: wurstmeister/ Kafka ports: - "9092:9092" - / var/log/kafka/logs: / var/docker kafka/logs # configuration environment variable environment: KAFKA_ADVERTISED_HOST_NAME: localhost KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181" KAFKA_BROKER_ID: 1 KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 KAFKA_CREATE_TOPICS: "stream-in:1:1,stream-out:1:1" depends_on KAFKA_CREATE_TOPICS: "stream-in:1:1,stream-out:1:1" -zoo1-redis (no actual container) # Container_name: kafkaCopy the code
Perform docker – compose
First upload docker-compos.yml to the server, then enter the directory and execute:
docker-compose up -d
Copy the code
Then start the background build service
If you want to start a separate service, you can:
Docker-compose up -d Specifies the service name. Example: docker-compose up -d zoo1Copy the code
Service scheduling cases
Simon Eureka: image: Simon/Eureka-server :2.0.1-SNAPSHOT hostname: Simon config: image: Simon /config-server:2.0.1-SNAPSHOT hostname: Depends_on: - simonConfig ports: - "8101:8101" depends_on: - simonEureka # always -- Always restart the container regardless of the exit status code. When always is specified, the Docker Daemon will restart the container an unlimited number of times. The container also tries to restart the daemon when it starts, regardless of the state of the container at the time. # no -- Do not restart the container automatically when it exits. This is the default. # on-failure[:max-retries] - Restarts only if the container exits with a non-zero status code. Optionally, the number of times you can exit the Docker Daemon and try to restart the container. # unless- Stopped - Always restart the container no matter what the exit status code is, but do not try to start the container if it is already stopped when the daemon starts. Depends_on: - "8102:8102" -SNAPSHOT ports: - "depends_on: -simoneureka -simonconfig restart: always # Monitor platform admin: image: Simon /admin:2.0.1 -snapshot ports: - "8103:8103" depends_on: - simonEureka - simonConfig restart: Always -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the author: AaronSimon sources: the original CSDN: https://blog.csdn.net/aaronsimon/article/details/82711610 copyright statement: This article is the blogger's original article, reprint please attach the blog link!Copy the code
At this time, the files in our server’s Simon directory should be as follows:
Apigateway: 2.0.1 - the SNAPSHOT. Jar admin: 2.0.1 - the SNAPSHOT. Jar config - server: 2.0.1 - the SNAPSHOT. The jar had - server: 2.0.1 - the SNAPSHOT. The jar docker-compose.ymlCopy the code
Pay attention to the point
If our yML file is not docker-comemage. yml, we need to specify the name of the yML file when arranging the service.
docker-compose -f docker-kafka.yml up -d
Copy the code
When we encounter the order of service startup, we can split docker-comemage. yml based on the order of service startup.
Docker-compose command
The command | describe |
---|---|
docker-compose up -d nginx | Build builds start the Nignx container |
docker-compose exec nginx bash | Log in to the nginx container |
docker-compose down | Delete all nginx containers, mirroring |
docker-compose ps | Display all containers |
docker-compose restart nginx | Restart the nginx container |
docker-compose run –no-deps –rm php-fpm php -v | Do not start the associative container in php-fpm and delete the container after executing PHP -v |
docker-compose build nginx | Build the mirror |
docker-compose build –no-cache nginx | Build without caching |
docker-compose logs nginx | View nginx logs |
docker-compose logs -f nginx | Verify (docker-comemess. yml) file configuration, if the configuration is correct, no output, when the file configuration is wrong, output error message |
docker-compose pause nginx | Pause the nignx container |
docker-compose unpause nginx | Restore the NINGx container |
docker-compose rm nginx | Delete containers (containers must be closed before deletion) |
docker-compose stop nginx | Stop the nignx container |
docker-compose start nginx | Start the Nignx container |
Recommended readingMore highlights
- Docker Compose is a docker compose tool for defining and running complex applications. One uses Doc… Yu Wei Read 3,033 comments 0 likes 2
- Docker Docker was founded by dotCloud founder Solomon Hykes in France… Blazzer Read 1,689 comments 0 likes 12
- Docker-compose: docker-compose: docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-compose Little Boy Read 6,517 comments 0 likes 5
- In the previous article Docker deployment Spring Boot, use Maven to build the image, and then use the Docker command to manipulate the container. Micro… AaronSimon Read 3,017 comments 0 Likes 13
- 2018-01-17 ZHIyimn read 42 Comments 1 Like 1