1

我正在尝试在我的 Mac(OS X Mavericks)上使用测试厨房(附带 ChefDK 并安装了 docker-api 驱动程序)在远程服务器上创建一个 docker 实例,但我似乎在最后一步几乎失败了:

stardust:test_kitchen rilindo$ kitchen create
-----> Starting Kitchen (v1.2.1)
-----> Creating <default-centos-64>...
       Step 0 : FROM centos:centos6
       ---> 68edf809afe7
       Step 1 : RUN yum clean all
       ---> Using cache
       ---> 79fd0e4588de
       Step 2 : RUN yum install -y sudo openssh-server openssh-clients curl
       ---> Using cache
       ---> 131f54051dc4
       Step 3 : RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
       ---> Using cache
       ---> d05a99414427
       Step 4 : RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
       ---> Using cache
       ---> 53636accc8b7
       Step 5 : RUN mkdir -p /var/run/sshd
       ---> Using cache
       ---> fa875c2e9f1a
       Step 6 : RUN useradd -d /home/kitchen -m -s /bin/bash kitchen
       ---> Using cache
       ---> 962000c5929d
       Step 7 : RUN echo kitchen:kitchen | chpasswd
       ---> Using cache
       ---> f22dcbca6292
       Step 8 : RUN echo 'kitchen ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
       ---> Using cache
       ---> cb9d8b95eb33
       Successfully built cb9d8b95eb33
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: Failed to complete #create action: [undefined method `[]' for nil:NilClass]
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

尝试创建容器端口时似乎失败了:

stardust:test_kitchen rilindo$ tail -30 .kitchen/logs/kitchen.log 
I, [2014-10-09T23:46:59.460656 #1112]  INFO -- Kitchen: -----> Starting Kitchen (v1.2.1)
I, [2014-10-09T23:46:59.525462 #1112]  INFO -- Kitchen: -----> Destroying <default-centos-64>...
I, [2014-10-09T23:47:02.720005 #1112]  INFO -- Kitchen: -----> Kitchen is finished. (0m3.26s)
I, [2014-10-09T23:48:49.778602 #1118]  INFO -- Kitchen: -----> Starting Kitchen (v1.2.1)
I, [2014-10-09T23:48:49.842909 #1118]  INFO -- Kitchen: -----> Creating <default-centos-64>...
E, [2014-10-09T23:48:52.826223 #1118] ERROR -- Kitchen: ------Exception-------
E, [2014-10-09T23:48:52.826280 #1118] ERROR -- Kitchen: Class: Kitchen::ActionFailed
E, [2014-10-09T23:48:52.826322 #1118] ERROR -- Kitchen: Message: Failed to complete #create action: [undefined method `[]' for nil:NilClass]
E, [2014-10-09T23:48:52.826363 #1118] ERROR -- Kitchen: ---Nested Exception---
E, [2014-10-09T23:48:52.826403 #1118] ERROR -- Kitchen: Class: NoMethodError
E, [2014-10-09T23:48:52.826442 #1118] ERROR -- Kitchen: Message: undefined method `[]' for nil:NilClass
E, [2014-10-09T23:48:52.826481 #1118] ERROR -- Kitchen: ------Backtrace-------
E, [2014-10-09T23:48:52.826520 #1118] ERROR -- Kitchen: /Users/rilindo/.chefdk/gem/ruby/2.1.0/gems/kitchen-docker-api-0.4.0/lib/kitchen/driver/docker.rb:228:in `container_ssh_port'
E, [2014-10-09T23:48:52.826560 #1118] ERROR -- Kitchen: /Users/rilindo/.chefdk/gem/ruby/2.1.0/gems/kitchen-docker-api-0.4.0/lib/kitchen/driver/docker.rb:82:in `create'
E, [2014-10-09T23:48:52.826600 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:273:in `public_send'
E, [2014-10-09T23:48:52.826641 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:273:in `block in perform_action'
E, [2014-10-09T23:48:52.826681 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:308:in `call'
E, [2014-10-09T23:48:52.826760 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:308:in `synchronize_or_call'
E, [2014-10-09T23:48:52.826802 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:283:in `block in action'
E, [2014-10-09T23:48:52.826842 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
E, [2014-10-09T23:48:52.826882 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:282:in `action'
E, [2014-10-09T23:48:52.826921 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:273:in `perform_action'
E, [2014-10-09T23:48:52.826961 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:252:in `create_action'
E, [2014-10-09T23:48:52.827001 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:246:in `block in transition_to'
E, [2014-10-09T23:48:52.827041 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:245:in `each'
E, [2014-10-09T23:48:52.827081 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:245:in `transition_to'
E, [2014-10-09T23:48:52.827149 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/instance.rb:108:in `create'
E, [2014-10-09T23:48:52.827189 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/command.rb:109:in `public_send'
E, [2014-10-09T23:48:52.827229 #1118] ERROR -- Kitchen: /opt/chefdk/embedded/apps/test-kitchen/lib/kitchen/command.rb:109:in `block (2 levels) in run_action'
E, [2014-10-09T23:48:52.827269 #1118] ERROR -- Kitchen: ----------------------

我不确定问题是否在于我的 .kitchen.yaml 中的端口是否正确转发。当然,这可能是一个完全不同的问题:

---
driver:
  name: docker
  socket: tcp://111.222.333.444:4243

provisioner:
  name: chef_solo

platforms:
  - name: centos-6.4
    driver_config:
      image: centos:centos6
      platform: centos
    forward:
    -  22:2222

suites:
  - name: default
    run_list:
    attributes:

我正在唱 adnichols/kitchen-docker-api 驱动程序,顺便说一句。

4

1 回答 1

1

事实证明,它失败了,因为 docker 无法分配端口:

Oct 10 22:05:04 traeger docker: [error] server.go:1013 Error: Cannot start container e92342347ce6e372ffcada89724067bc2878f00d5679e26ea849d4f49f275e1e: port has already been allocated
Oct 10 22:05:04 traeger docker: [error] server.go:90 HTTP Error: statusCode=500 Cannot start container e92342347ce6e372ffcada89724067bc2878f00d5679e26ea849d4f49f275e1e: port has already been allocated

在我的情况下,前向参数不是必需的。这是我现在正确的配置:

---
driver:
  name: docker
  socket: tcp://111.222.333.444:4243

provisioner:
  name: chef_solo

platforms:
  - name: ubuntu-12.04
    driver_config:
      privileged: true
      container_name: ubuntu_test_1204
      image: ubuntu:12.04
      platform: ubuntu
  - name: centos-6.4
    driver_config:
      privileged: true
      container_name: centos_test_6
      image: centos:centos6
      platform: centos

suites:
  - name: default
    run_list:
    attributes:

我现在可以连接到我的实例:

mylaptop:test_kit rilindo$ kitchen create default-centos-64
-----> Starting Kitchen (v1.2.1)
-----> Creating <default-centos-64>...
       Step 0 : FROM centos:centos6
       ---> 68edf809afe7
       Step 1 : RUN yum clean all
       ---> Using cache
       ---> 79fd0e4588de
       Step 2 : RUN yum install -y sudo openssh-server openssh-clients curl
       ---> Using cache
       ---> 131f54051dc4
       Step 3 : RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
       ---> Using cache
       ---> d05a99414427
       Step 4 : RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
       ---> Using cache
       ---> 53636accc8b7
       Step 5 : RUN mkdir -p /var/run/sshd
       ---> Using cache
       ---> fa875c2e9f1a
       Step 6 : RUN useradd -d /home/kitchen -m -s /bin/bash kitchen
       ---> Using cache
       ---> 962000c5929d
       Step 7 : RUN echo kitchen:kitchen | chpasswd
       ---> Using cache
       ---> f22dcbca6292
       Step 8 : RUN echo 'kitchen ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
       ---> Using cache
       ---> cb9d8b95eb33
       Successfully built cb9d8b95eb33
       Finished creating <default-centos-64> (0m3.70s).
-----> Kitchen is finished. (0m3.77s)
my laptop:test_kit rilindo$ kitchen login default-centos-64
kitchen@111.222.333.444's password: 
[kitchen@2bdd84c99337 ~]$ exit
于 2014-10-11T03:29:01.840 回答