加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用Ansible运行’docker volume create’?

发布时间:2020-12-16 03:33:36 所属栏目:安全 来源:网络整理
导读:我有一个Rails应用程序,我通过Ansible在Docker容器中部署.我的应用包括目前为止的三个容器: Docker卷容器(使用docker volume create name dbdata创建) Postgres容器(包含volumes_from dbdata) Rails应用程序容器(链接到postgres容器) 我的部署playbook正在

我有一个Rails应用程序,我通过Ansible在Docker容器中部署.我的应用包括目前为止的三个容器:

> Docker卷容器(使用docker volume create –name dbdata创建)
> Postgres容器(包含volumes_from dbdata)
> Rails应用程序容器(链接到postgres容器)

我的部署playbook正在运行,但我不得不通过SSH在服务器上运行docker volume create命令.我喜欢通过Ansible这样做,所以我可以将一个新的应用程序实例部署到一个空容器中.

有没有办法通过Ansible运行docker volume create,还是有其他方法可以做到这一点?我检查了Ansible Docker模块的文档,但看起来它们还不支持volume create.除非我错过了什么?

最佳答案
这是一个选项,使用命令模块.

- hosts: localhost
  tasks:
    - name: check if myvolume exists
      command: docker volume inspect myvolume
      register: myvolume_exists
      failed_when: false

    - name: create myvolume
      command: docker volume create --name myvolume
      when: myvolume_exists|failed

我们首先使用docker volume inspect检查卷是否存在.我们将该任务的结果保存在变量myvolume_exists中,然后我们只在检查任务失败时创建该卷.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读