Help us understand the problem. What is going on with this article?

AmazonLinuxでrubyからdocker apiを使う

More than 5 years have passed since last update.
$ ruby -r docker -e 'p Docker.version'
/usr/local/share/ruby/gems/2.0/gems/docker-api-1.19.0/lib/docker/connection.rb:50:in `rescue in request': Expected([200, 201, 202, 203, 204, 304]) <=> Actual(404 Not Found) (Docker::Error::NotFoundError)
    from /usr/local/share/ruby/gems/2.0/gems/docker-api-1.19.0/lib/docker/connection.rb:38:in `request'
    from /usr/local/share/ruby/gems/2.0/gems/docker-api-1.19.0/lib/docker/connection.rb:61:in `block (2 levels) in <class:Connection>'
    from /usr/local/share/ruby/gems/2.0/gems/docker-api-1.19.0/lib/docker.rb:94:in `version'
    from -e:1:in `<main>'

結論

  • docker-apiの要求するのとDockerが提供するAPIのバージョンが違った
$ ruby -r docker -e 'Docker.validate_version!'
/usr/local/share/ruby/gems/2.0/gems/docker-api-1.19.0/lib/docker.rb:118:in `rescue in validate_version!': Expected API Version: 1.16 (Docker::Error::VersionError)
    from /usr/local/share/ruby/gems/2.0/gems/docker-api-1.19.0/lib/docker.rb:115:in `validate_version!'
    from -e:1:in `<main>'
$ curl http://localhost:4243/version
{"ApiVersion":"1.15","Arch":"amd64","GitCommit":"c78088f/1.3.3","GoVersion":"go1.3.3","KernelVersion":"3.14.27-25.47.amzn1.x86_64","Os":"linux","Version":"1.3.3"}

解決方法

  • 現在のAmazonLinuxの最新でもAPI1.15なのでgemのバージョンを下げるしかない
$ gem install docker-api -v 1.18.0
$ ruby -r docker -e 'Docker.validate_version!; p Docker.version'
{"ApiVersion"=>"1.15", "Arch"=>"amd64", "GitCommit"=>"c78088f/1.3.3", "GoVersion"=>"go1.3.3", "KernelVersion"=>"3.14.27-25.47.amzn1.x86_64", "Os"=>"linux", "Version"=>"1.3.3"}
jrits
信頼と魅力のある先進のITをもとに、お客様のワークスタイル・イノベーションの実現を目指します。
http://www.jrits.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした