Docker Compose安装与简单使用
官网安装步骤地址:https://docs.docker.com/compose/install/#install-compose
一、docker-compose安装
1、安装
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
2、赋权
sudo chmod +x /usr/local/bin/docker-compose
3、测试(查看版本)
docker-compose --version
二、docker-compose.yml脚本
springboot项目为例,以镜像配置运行环境:docker中已有rest-api:0.0.1镜像,运行在8080端口,以profile为dev运行配置
version: "2"
services:
rest-api:
image: rest-api:0.0.1
ports:
- 8080:8080
environment:
- SPRING_PROFILES_ACTIVE=dev
以docker-compose.yml相同目录下的Dockerfile配置运行环境:
version: '2'
services:
rest-api:
build:
context: ./
dockerfile: Dockerfile-rest-api
restart: always
ports:
- 8080:8080
environment:
- SPRING_PROFILES_ACTIVE=dev
三、运行docker-compose.yml脚本
docker-compose up -d
四、关闭docker-compose.yml脚本
docker-compose down