阿里云centos 7.4 64位
yum安装
1)使用root权限登录系统
2)更新系统包到最新
yum -y update
使用官方安装脚本自动安装
安装命令如下:
- curl -fsSL https://get.docker.com | bash -s docker --mirror aliyun
也可以使用国内 daocloud 一键安装命令:
- curl -sSL https://get.daocloud.io/docker | sh
安装 Docker Engine-Community
安装最新版本的 Docker Engine-Community 和 containerd,或者转到下一步安装特定版本:
- sudo yum install docker-ce docker-ce-cli containerd.io
最后,别忘了启动docker
- systemctl start docker
2017.12 教程基于ubuntu下最新的compose版本3
参考链接:http://blog.csdn.net/pushiqiang/article/details/78682323
安装docker
Docker的社区版(Docker Community Edition)叫做docker-ce。老版本的Docker包叫做docker或者docker-engine,如果安装了老版本的docker得先卸载然后再安装新版本的docker。docker的发展非常迅速,apt源的更新往往比较滞后。所以docker官网推荐的安装方式都是下载docker安装脚本安装。
卸载老旧的版本(若未安装过可省略此步):
- $ sudo apt-get remove docker docker-engine docker.io
安装最新的docker:
- $ curl -fsSL get.docker.com -o get-docker.sh
- $ sudo sh get-docker.sh
shell会提示你输入sudo的密码,然后开始执行最新的docker过程
或者
- $ curl -sSL https://get.docker.com/ | sh
确认Docker成功最新的docker:
- $ sudo docker run hello-world
安装docker-compose
两种最新的docker安装方式
1.从github上下载docker-compose二进制文件安装
下载最新版的docker-compose文件
- $ sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
添加可执行权限
- $ sudo chmod +x /usr/local/bin/docker-compose
测试安装结果
- $ docker-compose --version
docker-compose version 1.16.1, build 1719ceb
2.pip安装
- $ sudo pip install docker-compose
docker-compose文件结构和示例
文件结构:docker-compose.yml:
- version: "3"
- services:
- redis:
- image: redis:alpine
- ports:
- - "6379"
- networks:
- - frontend
- deploy:
- replicas: 2
- update_config:
- parallelism: 2
- delay: 10s
- restart_policy:
- condition: on-failure
- db:
- image: postgres:9.4
- volumes:
- - db-data:/var/lib/postgresql/data
- networks:
- - backend
- deploy:
- placement:
- constraints: [node.role == manager]
- vote:
- image: dockersamples/examplevotingapp_vote:before
- ports:
- - 5000:80
- networks:
- - frontend
- depends_on:
- - redis
- deploy:
- replicas: 2
- update_config:
- parallelism: 2
- restart_policy:
- condition: on-failure
- result:
- image: dockersamples/examplevotingapp_result:before
- ports:
- - 5001:80
- networks:
- - backend
- depends_on:
- - db
- deploy:
- replicas: 1
- update_config:
- parallelism: 2
- delay: 10s
- restart_policy:
- condition: on-failure
- worker:
- image: dockersamples/examplevotingapp_worker
- networks:
- - frontend
- - backend
- deploy:
- mode: replicated
- replicas: 1
- labels: [APP=VOTING]
- restart_policy:
- condition: on-failure
- delay: 10s
- max_attempts: 3
- window: 120s
- placement:
- constraints: [node.role == manager]
- visualizer:
- image: dockersamples/visualizer:stable
- ports:
- - "8080:8080"
- stop_grace_period: 1m30s
- volumes:
- - "/var/run/docker.sock:/var/run/docker.sock"
- deploy:
- placement:
- constraints: [node.role == manager]
- networks:
- frontend:
- backend:
- volumes:
- db-data: