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

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

问题描述

简介



我在Azure中使用以下指南设置了Docker机器:






  • 此过程将创建的映像留在磁盘上。



    接下来我想做的是创建一个清理图像的夜间构建,我基本上创建了一个新的构建,并添加了以下步骤:


    1. 在以下之间显示停靠港图像:(docker images -a)

    2. Docker信息:(码头信息)

    3. docker rmi $(docker images -aq))

    4. 在以下之后显示码头图像:(docker图像-a)



    问题



    每当我运行这个构建,但我似乎收到以下错误:





    奇怪的是,这个命令docker images -aq在前面的步骤中工作正常:





    调查



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

      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'图像-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'注销**********

    此.cmd文件的结果:





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





    从PowerShell运行它可以正常工作:





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



    使用这些知识我将.cmd文件修改为.ps1文件,这似乎工作得更好一些。一个问题是,$(docker ....)从本地的docker安装获取了它的信息。我将脚本更改为以下内容,现在它可以从本地机器运行到Azure Linux Docker主机:

      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'图像-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'图像-aq)
    docker.exe -H tcp:// **********:2376 --tls --tlscacert ='ca.pem'--tlscert ='cert.pem' - -tlskey ='key.pem'注销**********

    所以基本上但是现在这个工作可以用Azure Docker构建步骤来实现吗?



    因为基本上似乎有是Azure Docker集成步骤的两个问题:


    1. 我认为这些命令运行在CMD而不是PowerShell中,这导致了 - / li>
    2. 当做一些像'docker -H .... rmi $(docker images -aq)'时,第二个docker命令(docker images ...)将与本地的docker实例。所以我实际上会喜欢一个解决方案,而无需手动提供IP地址和所有的证书。 (这个问题我可能会以一种奇怪的方式解决,如果我找不到一个很好的解决方案)


    解决方案

    我修改了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映像给出'未知的简写标志:''in -a'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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