Use Docker Compose application deployment SpringBoot

Use Docker Compose application deployment SpringBoot

Original: Dream de Star macrozheng June 19

Docker Compose is a tool definition and run multiple applications for docker containers. You can use Compose YAML file to configure your service applications, and then use a command, you can deploy all the services you configure a.

installation

Download Docker Compose:

curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

Modify the file permissions for the executable:

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

Check whether the installation was successful:

docker-compose --version

img

The step of using Docker Compose

  • Use Dockerfile custom application environment, the general need to modify the behavior when the initial image is required;
  • Use the application docker-compose.yml definitions need to deploy the service, in order to perform a one-time script deployment;
  • Use docker-compose up command to deploy all apps at once.

docker-compose.yml common commands

image

Specifies the name of the image runs

# 运行的是mysql5.7的镜像image: mysql:5.7

container_name

Configuration container name

# 容器名称为mysqlcontainer_name: mysql

ports

Specified host and port mapping of the container (HOST: CONTAINER)

# 将宿主机的3306端口映射到容器的3306端口ports:  - 3306:3306

volumes

The host file or directory into the vessel mount (HOST: CONTAINER)

# 将外部文件挂载到myql容器中volumes:  - /mydata/mysql/log:/var/log/mysql  - /mydata/mysql/data:/var/lib/mysql  - /mydata/mysql/conf:/etc/mysql

environment

Configuration environment variable

# 设置mysqlroot帐号密码的环境变量environment:  - MYSQL_ROOT_PASSWORD=root

Other services connected to the container ( the SERVICE: ALIAS )

# 可以以database为域名访问服务名称为db的容器links:  - db:database

Docker Compose commonly used commands

Build, create, start the relevant container:

# -d表示在后台运行docker-compose up -d

Stop all relevant container:

docker-compose stop

List all container information:

docker-compose ps

Use Docker Compose deploy applications

Write docker-compose.yml file

Docker Compose will manage the container is divided into three layers, engineering, services and containers. docker-compose.yml defined all the services make up a project, under the services nodes is the service, under the service container. Container and the container can be carried out directly between the service name as domain names, such as mall-tiny-docker-compose services through jdbc: mysql: // db: 3306 this address to access this mysql db service.

version: '3'services:  # 指定服务名称  db:    # 指定服务使用的镜像    image: mysql:5.7    # 指定容器名称    container_name: mysql    # 指定服务运行的端口    ports:      - 3306:3306    # 指定容器中需要挂载的文件    volumes:      - /mydata/mysql/log:/var/log/mysql      - /mydata/mysql/data:/var/lib/mysql      - /mydata/mysql/conf:/etc/mysql    # 指定容器的环境变量    environment:      - MYSQL_ROOT_PASSWORD=root  # 指定服务名称  mall-tiny-docker-compose:    # 指定服务使用的镜像    image: mall-tiny/mall-tiny-docker-compose:0.0.1-SNAPSHOT    # 指定容器名称    container_name: mall-tiny-docker-compose    # 指定服务运行的端口    ports:      - 8080:8080    # 指定容器中需要挂载的文件    volumes:      - /etc/localtime:/etc/localtime      - /mydata/app/mall-tiny-docker-compose/logs:/var/logs

Note: If you encounter mall-tiny-docker-compose the service can not connect to mysql, mysql database need to build mall while import mall.sql script. With particular reference to the use of Dockerfile SpringBoot Docker service run mysql application builder and the mirror portion is provided.

Use maven plug constructed mall-tiny-docker-compose mirroring

img

Note: Building a problem can refer to the use of Maven plugins to build Docker image

Run Docker Compose command to start all services

First docker-compose.yml uploaded to the Linux server, and then run the following command in the current directory:

docker-compose up -d

img

Access to interface documentation Address http://192.168.3.101:8080/swagger-ui.html:

img

Guess you like

Origin www.cnblogs.com/guoyinghome/p/11220332.html