skip to Main Content

I have a debian package I am deploying that comes with a docker image. On upgrading the package, the prerm script stops and removes the docker image. As a fail safe, I have the preinst script do it as well to ensure the old image is removed before the installation of the new image. If there is no image, the following error reports to the screen: (for stop) No such image: <tag> and (for rmi): No such container: <tag>.

This really isn’t a problem, as the errors are ignored by dpkg, but they are reported to the screen, and I get constant questions from the users is that error ok? Did the install fail? etc.

I cannot seem for find the correct set of docker commands to check if a container is running to stop it, and check to see if an image exists to remove it, so those errors are no longer generated. All I have is docker image tag to work with.

3

Answers


  1. I think you could go one of two ways:

    • Knowing the image you could check whether there is any container based on that image. If yes, find out whether that container is running. If yes, stop it. If not running, remove the image. This would prevent error messages showing up but other messages regarding the container and image handling may be visible.

    • Redirect output of the docker commands in question, e.g. >/dev/null

    Login or Signup to reply.
  2. you’re not limited with docker-cli you know? you can always combine docker-cli commands with linux sh or dos commands as well and also you can write your own .sh scripts and if you don’t want to see the errors you can either redirect them or store them to a file such as

    to redirect: {operation} 2>/dev/null
    to store : {operation} 2>>/var/log/xxx.log
    
    Login or Signup to reply.
  3. In your preinst script you could use docker images with a filter to check if the image is there. Then only take action if something is returned.

    E.g.

    docker images -af reference='your_debian_v*' -q
    

    will return the image id iff the reference matches.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search