删除远程Linux Azure托管的docker实例上未使用的docker映像会提供未知的简写标记:' a'.在-aq'中错误 [英] Removing unused docker images on a remote Linux Azure hosted docker instance gives 'unknown shorthand flag: 'a' in -aq' error

查看:97
本文介绍了删除远程Linux Azure托管的docker实例上未使用的docker映像会提供未知的简写标记:' a'.在-aq'中错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介

大家好,我使用以下指南在Azure中设置了Docker计算机:

  • 但是,此过程会将创建的图像保留在磁盘上.

    我接下来要做的是创建一个每晚生成的文件,以清理图像.我基本上创建了一个新版本,并添加了以下步骤:

    1. 之前显示docker映像:(docker images -a)
    2. Docker信息:(docker信息)
    3. 删除docker镜像:(docker rmi $ {docker images -aq))
    4. 在以下位置显示docker图像:(docker images -a)

    问题

    每当我运行此构建时,尽管我似乎都会收到以下错误:

    不过,奇怪的是,命令"docker images -aq"在之前的步骤中运行良好:

    调查

    我通过手动启动从我自己的计算机到远程docker主机的命令开始进行调查,但是以下.cmd文件也遇到了相同的问题:

      docker.exe -H tcp://**********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem'-tlskey ='key.pem'登录-u ********** -p ********** **********docker.exe -H tcp://**********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem'--tlskey ='key.pem图片-aqdocker.exe -H tcp://**********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem'--tlskey ='key.pem'rmi $(docker images -a)docker.exe -H tcp://**********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem'--tlskey ='key.pem' 登出 ********** 

    此.cmd文件的结果:

    从.cmd本地运行时,我看到相同的错误:

    从PowerShell运行它,但效果很好:

    编辑...(经过更多调查)

    利用这些知识,我将.cmd文件修改为一个.ps1文件,该文件似乎效果更好.一个问题是$(docker ....)是从本地docker安装获得的信息.我将脚本更改为以下脚本,现在它可以从本地计算机运行到Azure Linux docker主机:

      docker.exe -H tcp://**********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem'-tlskey ='key.pem'登录-u ********** -p ********** **********docker.exe -H tcp://**********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem'--tlskey ='key.pem图片-adocker.exe -H tcp://**********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem'--tlskey ='key.pem'rmi -f $(docker -H tcp://**********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem'--tlskey ='key.pem'图片-aq)docker.exe -H tcp://**********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem'--tlskey ='key.pem' 登出 ********** 

    因此基本上现在可以使用,但是,如何使它与Azure Docker构建步骤一起使用?

    因为基本上,Azure Docker集成步骤似乎存在两个问题:

    1. 我认为命令在CMD中而不是PowerShell中运行,这会导致-a错误
    2. 在执行类似"docker -H .... rmi $(docker images -aq)"的操作时,第二个docker命令(docker images ...)将与本地docker实例通信.因此,我实际上想要一个解决方案,而无需手动提供IP地址和所有证书.(即使找不到合适的解决方案,我也可以通过hacky的方式解决此问题)

    解决方案

    我修改了Docker VSTS任务以支持输出命令,以便可以链接多个Docker命令.

    我已经用它创建了一个Github存储库并提交了一个拉取请求:

    如果找到Docker映像,则将其删除

    Introduction

    Hi all, I set up a Docker machine in Azure using the following guides:

    I managed to get this all working and when doing a build on Windows I can now use the Linux Docker Host to create the docker image from the created sources. (By simply using the "Docker: Build an image" step followed by the "Docker: push an image" step with the DockerHostConnnection set to my Linux build machine:

    This process however leaves the created images on disk.

    What I wanted to do next is create a nightly build that cleans up the images. I basically created a new build and added the following steps:

    1. Show docker images before: (docker images -a)
    2. Docker Info: (docker info)
    3. Remove docker images: (docker rmi $(docker images -aq))
    4. Show docker images after: (docker images -a)

    Problem

    Whenever I run this build though I seem to receive the following error:

    The strange thing is though, is that the command "docker images -aq" worked fine in the step before:

    Investigation

    I started doing some investigation by manually kicking off the commands from my own computer to the remote docker host but am running into the same problems with the following .cmd file:

    docker.exe -H tcp://**********:2376 --tls --tlscacert='ca.pem' --tlscert='cert.pem' --tlskey='key.pem' login -u ********** -p ********** **********
    docker.exe -H tcp://**********:2376 --tls --tlscacert='ca.pem' --tlscert='cert.pem' --tlskey='key.pem' images -aq
    docker.exe -H tcp://**********:2376 --tls --tlscacert='ca.pem' --tlscert='cert.pem' --tlskey='key.pem' rmi $(docker images -a)
    docker.exe -H tcp://**********:2376 --tls --tlscacert='ca.pem' --tlscert='cert.pem' --tlskey='key.pem' logout **********
    

    Results of this .cmd file:

    When running it locally from .cmd I see the same error:

    Running it from PowerShell it works fine though:

    Edit... (After more investigation)

    Using this knowledge I modified the .cmd file to a .ps1 file which seemed to work a bit better. One problem was though that the $(docker ....) obtained it's information from the local docker installation. I changed the script to the following and now it works from my local machine to the Azure Linux docker host:

    docker.exe -H tcp://**********:2376 --tls --tlscacert='ca.pem' --tlscert='cert.pem' --tlskey='key.pem' login -u ********** -p ********** **********
    docker.exe -H tcp://**********:2376 --tls --tlscacert='ca.pem' --tlscert='cert.pem' --tlskey='key.pem' images -a
    docker.exe -H tcp://**********:2376 --tls --tlscacert='ca.pem' --tlscert='cert.pem' --tlskey='key.pem' rmi -f $(docker -H tcp://**********:2376 --tls --tlscacert='ca.pem' --tlscert='cert.pem' --tlskey='key.pem' images -aq)
    docker.exe -H tcp://**********:2376 --tls --tlscacert='ca.pem' --tlscert='cert.pem' --tlskey='key.pem' logout **********
    

    So basically this now works, however, how can I get this to work with the Azure Docker build steps?

    Because basically there seem to be 2 problems with the Azure Docker Integration steps:

    1. I think the commands run in CMD instead of PowerShell which results in the -a error
    2. When doing something like: 'docker -H .... rmi $(docker images -aq)', the second docker command (docker images...) will talk to the local docker instance. So I would actually like a solution for this without having to manually provide the IP address and all the certificates. (This problem I can probably solve in a hacky way though if I can't find a good solution)

    解决方案

    I've modified the Docker VSTS task to support an output command so that chaining multiple Docker commands is possible.

    I've created a Github repository with this and submitted a pull request: https://github.com/devedse/vsts-docker

    In the following example I use the output variable to first obtain the Docker images and then remove them. Using the, just released, functionality of conditional tasks in VSTS I also managed to make VSTS build skip the "Remove the images" step whenever there is no image found.

    Obtaining the Docker images:

    Removing the Docker images if there are any found

    这篇关于删除远程Linux Azure托管的docker实例上未使用的docker映像会提供未知的简写标记:' a'.在-aq'中错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆