简体   繁体   English

使用Ansible部署最新的Docker容器

[英]Deploying latest docker containers with ansible

I have been trying to get ansible to deploy my containers, and I have been successful with the following config, but the problem I am running into is that it will not start the most recent version of my container. 我一直在尝试部署容器,并且已经成功完成了以下配置,但是遇到的问题是它将无法启动容器的最新版本。

- name: Deploy
  hosts: staging
  tasks:
    - name: Install docker-py
      pip: name=docker-py
    - name: Pull latest container
      raw: docker pull org/proj:latest
    - name: Stop container
      docker:
        image="org/proj:latest"
        name=proj-rails
        state=stopped
    - name: Deploy container
      docker:
        image="org/proj:latest"
        name=proj-rails
        ports=80:80
        state=running

I can build and push new containers to docker hub and try to pull them down. 我可以构建新容器并将其推入docker hub并尝试将其拉低。 On the server docker images lists the latest containers: 在服务器上, docker images列出了最新的容器:

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
org/proj            latest              9f0de94df28c        2 hours ago         675.5 MB
<none>              <none>              15f4bbbeebca        2 days ago          670.6 MB
<none>              <none>              f7958247ed52        2 days ago          670.3 MB

My problem is that ansible keeps starting 15f4bbbeebca (which is not the latest container). 我的问题是,ansible会继续启动15f4bbbeebca(这不是最新的容器)。 Can anyone help me figure out what is wrong? 谁能帮助我找出问题所在?

Shot in the dark, but that syntax looks odd to me. 在黑暗中拍摄,但是这种语法对我来说很奇怪。 Shouldn't it be 不是吗

- name: Stop container
  docker:
    image: org/proj:latest
    name: proj-rails
    state: stopped

?

Also, why are you using raw rather than command (or shell)? 另外,为什么要使用原始而不是命令(或shell)?

Is it possible that the issue arises from the misunderstood latest tag? 该问题是否可能是由于误解了 latest标签引起的? see this https://medium.com/@mccode/the-misunderstood-docker-tag-latest-af3babfd6375#.hlzfep7mn 看到这个https://medium.com/@mccode/the-misunderstood-docker-tag-latest-af3babfd6375#.hlzfep7mn

I fixed my issues by writing my own deployment solution and then open sourced it, https://github.com/mrinterweb/freighter 我通过编写自己的部署解决方案来解决问题,然后将其开源, https://github.com/mrinterweb/freighter

I designed freighter to be easily configurable and flexible at the same time. 我设计的货机同时易于配置和灵活。 I hope someone finds it to be helpful. 我希望有人发现它会有所帮助。 I am not finished with freighter yet, but it is usable at this point. 我还没有完成货轮,但是现在可以使用。

I realize that this does not answer the question about how to deploy docker with ansible, but I gave up on trying to deploy containers with ansible. 我意识到这并不能回答有关如何使用ansible部署docker的问题,但是我放弃了尝试使用ansible部署容器的问题。 I just did not find the ansible docker module to be mature enough, documented enough, or configurable to my needs. 我只是发现ansible docker模块不够成熟,没有足够的文档记录或无法满足我的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM