如何使用ansible docker_image模块标记本地docker镜像?

时间:2016-07-03 10:56:38

标签: image docker ansible

我正在制作本地泊坞窗图片并且我想对其进行标记,但我不知道如何为我刚刚在本地构建的泊坞窗图像填充repository字段。 / p>

是否可以使用docker_image模块标记本地图像?

3 个答案:

答案 0 :(得分:4)

您可以在一个命令中构建和标记。如果您希望它保持在本地,则不能在名称中包含存储库(no /)。标签只相当于“最新”。所以结果看起来像是:

  - name: 'Build an image with a tag'
    docker_image:
      path: .
      name: ansible-module
      tag: v1
      state: present

结果如下:

$ docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
ansible-module              v1                  39be0dcc8dfa        2 minutes ago       1.093 MB

如果您想要包含注册表URL或存储库名称(docker hub login)并且不想在构建后自动推送,我不相信您可以使用此Ansible插件。

更新,对于其他标记,您可以执行以下操作:

  - name: 'Build an image'
    docker_image:
      path: .
      name: ansible-module
      tag: v1
      state: present
    register: docker_build

  - name: 'Retag image'
    shell: docker tag ansible-module:v1 ansible-module:dev
    when: docker_build.changed

答案 1 :(得分:3)

似乎docker_image有更好的解决方案:

tasks:
  - name: build_image
    docker_image:
      name: test_img:latest     # Name of image, may be with repo path.
      path: .
      state: present
    register: image_build

  - name: tag_version
    docker_image:
      name: test_img:latest     # Equal to name in build task.
      repository: test_img:1.2  # New tag there.
      pull: no
      state: present
    when: image_build.changed

效果:

    $ docker images
    REPOSITORY   TAG       IMAGE ID            CREATED              SIZE
    test_img     1.2       ab14e8cce7ef        9 seconds ago        142MB
    test_img     latest    ab14e8cce7ef        9 seconds ago        142MB

也可以推送回购(需要将名称更改为完整的回购路径)。

答案 2 :(得分:1)

我能够发现var fileMap = new ConfigurationFileMap("D:AWS\\CoreLocalSettings.config"); var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap); var sectionGroup = configuration.GetSectionGroup("applicationSettings"); 模块的repository只是图片在本地构建时的名称。

首先使用标记docker_image构建图像,然后为其添加标记。

latest