Scan docker images with Trivy from within a docker container - docker

Problem
I would like to do the following:
Create an image with Trivy and Docker installed
Run the container on Kubernetes
Schedule a CRON job to pull all images from a container registry and to scan them, and output the results to stdout
Question
Is there a smart way to do this? Can you even install docker within a docker container?

I ended up doing the following:
Creating an image with Trivy and Skopeo installed
Downloading the docker images with Skopeo
skopeo copy --src-creds=user:password --dest-compress --src-tls-verify=false docker://myrepo.com/mynamespace/ubuntu:latest oci:ubuntu
Scanning the image
trivy image --input ubuntu
An alternative to Skopeo would be to use the Registry HTTP API to download images as suggested by David Maze.

Related

Can you download a docker image from a repository to a docker container without a running docker daemon?

I have a docker container with Trivy installed.
I have a remote registry with docker images.
and
I would like to download the docker images to the container for scanning
Challenges
It is hard to run docker within a docker container for pulling the images.
Trivy requires that you have the images locally before it can scan the images, either in a local registry or as a file.
I found two solutions:
Download the images with Skopeo
Download the images with the HTTP API V2
For the API I had a hard time making the authentication work, as it is repository specific, and Scaleways' authentication had unexpected behaviour.

Can Docker CLI, Podman and other similar tools have shared local storage for images?

I recently started using podman and realized that images pulled via docker doesn't become available for use to podman and vice-versa. For example:-
If I pull the image using docker CLI, as shown below
docker pull registry.access.redhat.com/ubi7-minimal
and If I want to use the same image with podman or buildah, turns out I cannot
[riprasad#localhost ~]$ podman inspect registry.access.redhat.com/ubi7-minimal
Error: error getting image "registry.access.redhat.com/ubi7-minimal": unable to find 'registry.access.redhat.com/ubi7-minimal' in local storage: no such image
I understand that this is because both podman and docker uses a different storage location and hence the image pulled down via docker doesn't becomes available for use with podman and vice-versa.
[riprasad#localhost ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.access.redhat.com/ubi7-minimal latest fc8736ea8c5b 5 weeks ago 81.5MB
[riprasad#localhost ~]$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
Is there a way to mitigate this issue, and somehow make docker and podman work inter-changeably on the very same image, irrespective of whether it has been pulled down via docker or podman ??
Docker and Podman do not sure the same storage. They can not, because Docker controls locking to its storage within the daemon. While Podman, Buildah, CRI-O, Skopeo all can share content, because they use the file system.
Podman and the other tools can work with the docker-daemon storage indirectly, via the "docker-daemon" transport.
Something like:
podman run docker-daemon:alpine echo hello
Should work.
Note, that podman is pulling the image out of the docker daemon and is storing the image in containers/storage, and then running the container, it is not using the Docker storage directly.
You can also do
podman push myimage docker-daemon:myimage
To copy an image from containers/storage into the docker daemon.
Adding to #rhatdan's post
podman run docker://alpine echo hello
This worked for me.
For more details: Here->

Docker pull hello-world showing successful create but when using docker ps or docker ps -a not shoing images

I used docker ps/docker ps -a/docker ps -n 1 all not showing my first image.
But it after I using docker pull hello-world it saying it installed successfully
docker pull pulls an image (and all the layers that make it up) to your local machine, but doesn't run anything.
docker ps lists containers on your system.
Once you run that container (using docker run hello-world), you'll see it in dokcer ps.
To view the image you pulled, you could use docker images.
As you find from the previous answer docker pull will download the image (mostly from the docker hub) and when trying to pull next time, it finds the image already in your local machine. To see all the images you have locally, use docker image ls.

Docker Image history without using docker history command

I have a docker image. I want to analyze the docker image history, for this I can use docker image history command in the docker installed environment.
But when am working in a Openshift cluster, I may not have the access to the docker command here. So here I want get the docker history command result for the given image.
So basically I have a docker image and I don't have docker installed there. In this case how can we get the history of that docker image?
Can anyone please help me on this?
You can get the registry info either via curl or skopeo inspect. But the rest of the metadata is stored inside the image itself so you do have to download at least the final layer.

Is there an official Docker image for Elastic Filebeat?

Is there an official Docker image for Elastic Filebeat?
I see there are some community contributed ones, not sure if there is an official one.
Information about the official Docker images for Elastic Beats can be found at https://www.docker.elastic.co/#beats. The images are hosted in Elastic's container registry and not Docker Hub.
You can use the image with a command like:
docker run -v /var/log:/mnt/log docker.elastic.co/beats/filebeat:6.1.1
Or you can build your own image with customized config using a Dockerfile like:
FROM docker.elastic.co/beats/filebeat:6.1.1
COPY filebeat.yml /usr/share/filebeat/filebeat.yml
The images' source can be found at https://github.com/elastic/beats-docker.

Resources