Product Docs
-
-
-
-
-
-
-
- chainctl
- chainctl auth
- chainctl auth configure-docker
- chainctl auth login
- chainctl auth logout
- chainctl auth pull-token
- chainctl auth status
- chainctl auth token
- chainctl config
- chainctl config edit
- chainctl config reset
- chainctl config save
- chainctl config set
- chainctl config unset
- chainctl config validate
- chainctl config view
- chainctl events
- chainctl events subscriptions
- chainctl events subscriptions create
- chainctl events subscriptions delete
- chainctl events subscriptions list
- chainctl iam
- chainctl iam account-associations
- chainctl iam account-associations check
- chainctl iam account-associations check aws
- chainctl iam account-associations check gcp
- chainctl iam account-associations describe
- chainctl iam account-associations set
- chainctl iam account-associations set aws
- chainctl iam account-associations set gcp
- chainctl iam account-associations unset
- chainctl iam account-associations unset aws
- chainctl iam account-associations unset gcp
- chainctl iam folders
- chainctl iam folders delete
- chainctl iam folders describe
- chainctl iam folders list
- chainctl iam folders update
- chainctl iam identities
- chainctl iam identities create
- chainctl iam identities create github
- chainctl iam identities create gitlab
- chainctl iam identities delete
- chainctl iam identities describe
- chainctl iam identities list
- chainctl iam identities update
- chainctl iam identity-providers
- chainctl iam identity-providers create
- chainctl iam identity-providers delete
- chainctl iam identity-providers list
- chainctl iam identity-providers update
- chainctl iam invites
- chainctl iam invites create
- chainctl iam invites delete
- chainctl iam invites list
- chainctl iam organizations
- chainctl iam organizations delete
- chainctl iam organizations describe
- chainctl iam organizations list
- chainctl iam role-bindings
- chainctl iam role-bindings create
- chainctl iam role-bindings delete
- chainctl iam role-bindings list
- chainctl iam role-bindings update
- chainctl iam roles
- chainctl iam roles capabilities
- chainctl iam roles capabilities list
- chainctl iam roles create
- chainctl iam roles delete
- chainctl iam roles list
- chainctl iam roles update
- chainctl images
- chainctl images diff
- chainctl images history
- chainctl images list
- chainctl images repos
- chainctl images repos build
- chainctl images repos build apply
- chainctl images repos build edit
- chainctl images repos build list
- chainctl images repos build logs
- chainctl images repos list
- chainctl packages
- chainctl packages versions
- chainctl packages versions list
- chainctl update
- chainctl version
Open Source
Education
Debugging Distroless Containers with Docker Debug
Tools used in this video
- Docker Desktop (Note a paid subscription is required.)
Transcript
Hey folks, I wanted to record a short video explaining how you can debug container images, even distroless ones.
One of the problems with distroless images is that they can be difficult to debug.
Now if you’re using Kubernetes, please try out ephemeral containers, but in this video I want to talk about something else.
In Docker desktop 4.27 they have a beta feature called debug, and I’m going to demonstrate that now.
So I’m going to start a Chainguard nginx image.
Note that Chainguard nginx images run on port 8080 for security reasons.
Now that should be running in the background, so if I switch to my browser and we hit reload, yep nginx is there and running.
So say I want to debug this nginx container, say it’s not displaying the right content or it can’t reach another container, something like that.
So typically what you might want to do is use docker exec
to get a shell into the container.
But if I try to run bash, I get told there is no bash, and I get told there is no sh.
And even if I get the full path, it doesn’t work.
Because this is a distroless container, there’s no shell available to me.
There are also very few utils.
So I can’t even run ping
for example.
So the only way to debug this container at the minute is from the outside, if you like.
Or is it?
Because with Docker 4.27, I now have this debug
command.
So if I run docker debug debug test
, this is what happens.
And suddenly I have a shell into the container.
Basically what’s happened is it’s side loaded a Nix environment into the container.
And from here I can install tools to debug things.
It also has a linting tool to check the entry point.
So you can see the entry point here is fine.
It does have editors, et cetera.
I believe ping
is here.
Yep.
So what can we do?
We can also look at the container file system and edit it live.
So for example, if I do /etc/nginx
, and autocomplete works, and here’s the default conf, and there’s the location of the nginx files.
So let’s take a look at these nginx files.
And here’s index.html.
And this is welcome to nginx.
So let’s try live editing this.
Okay.
I saved that.
Now let’s go back to our browser and reload it.
Yeah.
So there we are.
I’ve live edited a distroless container that had no shell and no editor inside it.
So there is more you can do.
You can install further tooling, but like I said, it does have some basic tooling with it.
But like say, I don’t know if you want to install a different editor, you can definitely do that.
So here we go.
There’s install emacs.
Note this is a beta version.
So I have noticed this error coming up a few times or warning.
I do believe it’s actually innocuous and hopefully that will be changed in newer versions, but it has actually installed emacs there.
Now I don’t use emacs.
So I always have to struggle to escape.
Is it control?
Oh, no.
There we go.
Okay.
So there you go.
That’s how you can debug a distroless container using the new Docker debug feature.
Please do give it a go and let me know how you get on.
Relevant Resources
- Debugging Distroless Container Images with Kubectl Debug and CDebug (Video)
- Debugging Distroless Container Images (Article)
Last updated: 2024-12-12 15:21