Terraform 无法启动 jenkins 容器?

Terraform failling to start jenkins container?

我正在尝试使用 terraform 实现一个非常简单的基于配置的 jenkins 镜像拉取(通过 docker hub),然后启动镜像。这是这种情况下我唯一想要的,但是有了这个配置文件...

# Start a container
resource "docker_container" "jenkins" {
  name = "jenkins_tf_server"
  image = "${docker_image.jenkins.latest}"
  command = ["docker run -p 8080:8080 -p 50000:50000 -v /jenkins:/var/jenkins_home -d jenkins"]
}

# Find the latest Ubuntu precise image.
resource "docker_image" "jenkins" {
  name = "jenkins"
}

...我 运行 遇到了两种奇怪的情况。

第一个是 Terraform,当执行 terraform apply 就完成了这么多并挂起...

$ terraform apply
docker_image.ubuntu: Refreshing state... (ID: )
docker_image.jenkins: Creating...
  latest: "" => "<computed>"
  name:   "" => "jenkins"

我一开始以为是因为它正在下载荒谬数量的 jenkins 图像。我在大约 15 分钟后检查并使用 docker images

找到了以下内容
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              precise             e1917e6028b6        6 days ago          138.4 MB
adron/dock-base     latest              19322f24adb5        3 weeks ago         417.1 MB
jenkins             1.596.2             b89edf070767        11 months ago       662 MB
jenkins             1.596.1             10929b1bd6c1        12 months ago       662 MB
jenkins             1.596               484633fa05c1        15 months ago       661.7 MB
jenkins             1.595               218ccb377abc        15 months ago       661.7 MB
jenkins             1.594               a0e66c091a65        15 months ago       661.7 MB
jenkins             1.593               d1a051ab9181        15 months ago       661.7 MB
jenkins             1.580.2             a1760aac28b5        15 months ago       661.5 MB
jenkins             1.592               5b1c9d13e15f        15 months ago       661.7 MB
jenkins             1.591               1ed19954eb17        15 months ago       661.7 MB
jenkins             1.590               32a506f5f209        15 months ago       661.7 MB
jenkins             1.589               03046b8487c8        15 months ago       661.7 MB
jenkins             1.588               4808c4dcd370        15 months ago       661.7 MB
jenkins             1.587               46e316ce7c55        15 months ago       661.7 MB
jenkins             1.586               564cf586884f        15 months ago       661.5 MB
jenkins             1.585               095470f5ded4        15 months ago       661.4 MB
jenkins             1.584               4ce45cf2ba35        15 months ago       661.4 MB
jenkins             1.583               c247e6c41208        15 months ago       661.4 MB
jenkins             1.582               1db2820094fc        15 months ago       661.3 MB
jenkins             1.581               89a7e4784544        15 months ago       661.3 MB
jenkins             1.580               96c035d55481        15 months ago       661.3 MB
jenkins             1.580.1             d0580748a09e        15 months ago       661.5 MB
jenkins             1.579               d25e714f32ca        15 months ago       661.3 MB
jenkins             1.578               f27551f8a09e        15 months ago       661.3 MB
jenkins             1.577               08f7a353bb4b        15 months ago       661.3 MB
jenkins             1.576               7a0b44cc2593        15 months ago       661.4 MB
jenkins             1.575               4c4d8a34c3e9        15 months ago       661.4 MB
jenkins             1.574               5594009b4711        15 months ago       661.4 MB
jenkins             1.573               0cb884316533        15 months ago       661.4 MB
jenkins             1.572               be6b4f62a56d        15 months ago       661.3 MB
jenkins             1.571               550ab6938ec7        15 months ago       661.3 MB
jenkins             1.570               5deaae34589f        15 months ago       661.3 MB
jenkins             1.569               a02a7a601061        15 months ago       661.3 MB
jenkins             1.568               d7962fb8c99d        15 months ago       661.3 MB
jenkins             1.567               5076e78cad90        15 months ago       661.6 MB
jenkins             1.566               92a0fc7edfde        15 months ago       661.6 MB
jenkins             1.565               9ac08ed3d170        15 months ago       661.6 MB
jenkins             1.565.3             f32746929b80        15 months ago       661.4 MB
jenkins             1.565.2             7fcc53e58943        15 months ago       661.6 MB
jenkins             1.565.1             f2bf74880f3f        15 months ago       661.6 MB
jenkins             1.564               52abe54f3761        15 months ago       661.6 MB
jenkins             1.563               5dc5fa40c284        15 months ago       661.6 MB
jenkins             1.562               10281098ecaf        15 months ago       661.6 MB
jenkins             1.561               0041414dfbce        15 months ago       661.6 MB
jenkins             1.560               5a0403999187        15 months ago       661.4 MB
jenkins             1.559               f2794ccd4e2d        15 months ago       661 MB
jenkins             1.558               2ef2f3c7344c        15 months ago       660.9 MB
jenkins             1.557               4eca249661ab        15 months ago       660.8 MB
jenkins             1.556               7721817b7521        15 months ago       660.8 MB
jenkins             1.555               30da00a4e34e        15 months ago       660.7 MB
jenkins             1.554.3             37c6c23e2279        15 months ago       661.1 MB
jenkins             1.554.2             eda292ef5358        15 months ago       661.1 MB
jenkins             1.554.1             c00816fce587        15 months ago       660.9 MB
jenkins             1.554               c0ee99758afa        20 months ago       748.8 MB

我不知道 terraform 究竟发生了什么并决定做什么。关于如何让它运行并简单地使用 terraform 文件中上面列出的 command 参数中的 docker 命令启动图像的任何想法?

这看起来像是典型的 shell 通配扩展错误。

错误在

image = "${docker_image.jenkins.latest}"

请记住,在操作时 latest 被转换为最近添加的标签。

固定版本或获取旧图像。