我是Docker世界的新手,我度过了我的假期来学习这个码头(但它比Vagrant更难).
所以我使用Ubuntu 16.04,我成功安装了docker和docker-compose.
我读了这个教程:Quickstart: Docker Compose and Rails
但这不起作用……也许教程不好.
我有这个docker-compose.yml:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/www/html
ports:
- "3000:3000"
depends_on:
- db
我总是得到这个错误:
$docker-compose run web rails new . --force --database=postgresql --skip-bundle
ERROR: Validation Failed in file './docker-compose.yml',reason(s):
Unsupported config option for 'web' service: 'depends_on'
嗯,好吧,我看了很多谷歌的结果,似乎我遇到了麻烦,因为我使用的是Ubuntu.不幸的是,Ubuntu中最高版本的docker只有1.5.2. (我尝试用curl下载1.7.1,但是自动安装了1.5.2.)
$docker version
Client:
Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Tue Apr 26 23:43:49 2016
OS/Arch: linux/amd64
Server:
Version: 1.11.1
API version: 1.23
Go version: go1.5.4
Git commit: 5604cbe
Built: Tue Apr 26 23:43:49 2016
OS/Arch: linux/amd64
你有任何想法,我怎么能运行基于rails的docker?
我无法安装docker机器,因为我使用ubuntu并且安装总是会失败.
但是我的PHP docker-compose.yml很好,因为我可以运行它:slight_smile:但这个rails教程并不好.
因为,看看docker版本,你应该使用高于1.6.x的docker-compose版本.
要识别这一点,您可以运行
$docker-compose -v
在我的情况下,让我
docker-compose version 1.7.0,build 0d7bf73
如果你的版本有1.7.x或更高版本,那么下面的信息绝对适用于你.
这应该是有效的:
version: '2' ## <- this line matter and you removed it out the tutorial
services: ## <- this line also
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/www/html
ports:
- "3000:3000"
depends_on:
- db
There are currently three versions of the Compose file format:
- Version 1,the legacy format. This is specified by omitting a version
key at the root of the YAML.- Version 2.x. This is specified with a version: ‘2’ or version: ‘2.1’
entry at the root of the YAML.- Version 3.x,the latest and recommended version,designed to be
cross-compatible between Compose and the Docker Engine’s swarm mode.
This is specified with a version: ‘3’ or version: ‘3.1’,etc.,entry
at the root of the YAML.
另外,这里有一个小的docker-composeversion / Composer文件矩阵:
Compose file format | Docker Engine release --------------------|---------------------- 3.0 ; 3.1 | 1.13.0+ 2.1 | 1.12.0+ 2.0 | 1.10.0+ 1.0 | 1.9.1.+
资料来源:from docker documentation
- Version 1 is supported by Compose up to 1.6.x. It will be deprecated in a future Compose release.
- Version 2 files are supported by Compose 1.6.0+ and require a Docker Engine of version 1.10.0+.
- An upgrade of version 2 that introduces new parameters only available with Docker Engine version 1.12.0+
- An upgrade of version 2.1 that introduces new parameters only available with Docker Engine version 1.13.0+. This version also allows to specify default scale numbers inside the service’s configuration.
- Designed to be cross-compatible between Compose and the Docker Engine’s swarm mode,version 3 removes several options and adds several more.
在docker文档页面上,现在还有关于如何升级Compose文件的实用指南:
> One to upgrade from 1 to 2.x
> One to upgrade from 2.x to 3.x
其他有用的docker撰写文档:
> List of all docker-compose
versions
> Compose file version
1
> Compose file version
2
> Compose file version
3 (current)