Skip to content

docker-compose

简介

docker-compose和docker是一对好伙伴,一般用docker-compose方便管理镜像和容器,因为手动敲docker命令实在记不住也容易出错。

安装

下载

bash
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

添加可执行权限

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

建立软连接

bash
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

使用

新建compose.yml文件

yaml
version: '3'
services:
  fastposter:
    container_name: fastposter
    image: fastposter/fastposter
    ports:
      - 5000:5000
    environment:
      POSTER_URI_PREFIX: http://127.0.0.1:5000/
version: '3'
services:
  fastposter:
    container_name: fastposter
    image: fastposter/fastposter
    ports:
      - 5000:5000
    environment:
      POSTER_URI_PREFIX: http://127.0.0.1:5000/

创建并启动容器

bash
docker-compose up
docker-compose up

参考