Docker's compose

Most of the notes carry the advanced version of Java's Docker at station B. By the way, the pictures and texts are combined and recorded, which is easy to review and is only used for learning!
Video address: https://www.bilibili.com/video/BV1kv411q7Qc The author is really very good, don't prostitute for nothing, remember three consecutive
If there is any infringement, please contact to delete!

1. Concept

docker compose: to build and manage multiple services in Docker containers.
Source address : https://github.com/docker/compose
Official website : https://docs.docker.com/compose/Online
learning website : https://vuepress.mirror.docker-practice.com/compose/introduction/

2. Docker Compose three steps

  1. Use a to define the application's environment so that it can be replicated anywhere. Dockerfile
  2. Define the services that make up your application so that they can run together in an isolated environment. docker-compose.yml
  3. Finally, run and compose will get your entire application up and running. docker-compose up

Official website: A docker-compose is similar to this.
insert image description here
If we need to start 100 services, we only need to configure it in docker-compose.yml and start it through docker-compose up!
compose important concepts:

  • Service: An application container, which 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.

3. Install Compose

# 官网提供 (没有下载成功)
curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
 
# 国内地址
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

insert image description here
Check if the installation is successful!
insert image description here
Granted permission

sudo chmod +x /usr/local/bin/docker-compose

insert image description here
insert image description here
Solution to unsuccessful installation : https://blog.csdn.net/qq_35663625/article/details/107411857

Check the installed version
insert image description here

4. Uninstall Compose

If it is installed as a binary package, delete the binary file.

sudo rm /usr/local/bin/docker-compose

If it is installed through pip, execute the following command to delete it.

sudo pip uninstall docker-compose

5. Experience Compose

Reference official website : https://docs.docker.com/compose/gettingstarted/

insert image description here
insert image description here
docker ps
insert image description here
docker images
insert image description here
process:

创建网络
执行Docker-compose.yaml
启动服务
yaml规则
docker-compose.yaml 核心!

View Gateway
insert image description here

[root@localhost composetest]# docker network inspect composetest_default

It is found that it is in the same gateway, what does it mean?
If we are on the same network, we can access it directly through the domain name.
insert image description here
stop:

docker-compose dowm
或者
Ctrl+C
以前:通过docker run一个一个启动服务;
现在:通过docker-compose编写yaml一键启动服务。

6. yaml rules

Reference URL : https://docs.docker.com/compose/compose-file/

# 3层!
version: ' '#版本
services: #服务
	服务1: web
		#服务配置
		images
		build
		network
	服务2: redis
	服务3: redis
#其他配置网络/卷、全局规则
volumes:
networks :
configs:

insert image description here
used in the cluster
insert image description here

7. One-click deployment of WP blog

Official website reference : https://docs.docker.com/samples/wordpress/

7.1 Create a folder

Create a folder named my_wordpress in the /home directory
insert image description here

7.2 Writing yaml files

version: "3.9"
    
services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - wordpress_data:/var/www/html
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
volumes:
  db_data: {
    
    }
  wordpress_data: {
    
    }

7.3 Startup

[root@localhost my_wordpress]# docker-compose up

insert image description here
Check whether the opening is successful:
insert image description here
Test: Access through ip: 8000 port number
insert image description here

8. The actual combat process

1. Write project
microservices 2. Dockerfile builds mirrors
3. docker-compose.yaml arranges projects
4. Throw it to the server docker-compose up

Summary:
As long as there are docker-compose files in future projects. According to this rule, start the orchestration container. !
Company: docker-compose. Start directly.
Online open source project: docker-compose - key to get it.

Suppose the project is to be redeployed and packaged

docker-compose up --build #重新构建!

Guess you like

Origin blog.csdn.net/Yearingforthefuture/article/details/120176020