ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Follow publication

Member-only story

Docker Debug beta

Mohammad-Ali A'RÂBI
ITNEXT
Published in
6 min readFeb 5, 2024

Docker Debug is a new feature available from Docker Desktop 4.27.0 that allows you to attach a shell to Docker container or image, even though they have no shell available. The feature helps engineers to debug their containers and images without having to install additional tools in them. Docker Debug comes with a pre-installed set of tools, like editors, ping, etc., but you can also install your own tools.

How to Use Docker Debug

To use Docker Debug, you need to have Docker Desktop 4.27.0 or later installed. Also, the beta version is only available for Pro subscribers.

To make sure the feature is available, run the following command:

docker debug --help

Create an Image with No Shell

Let’s first create a Docker image with no shell available. What follows is a Dockerfile based on scratch image. In the first stage, we create a binary file called hello and copy it to the second stage.

Create a Go file called main.go with the following content:

package main

import (
"fmt"
"time"
)
func main() {
for {
fmt.Println("Hello, Wowlrd!")
time.Sleep(5 * time.Second)
}
}

It will print Hello, Wowlrd! every 5 seconds. Now, create a Dockerfile with the following content:

FROM golang:1.17.2-alpine3.14 AS builder

WORKDIR /app
COPY main.go .
RUN go build -o hello main.go

# ------------------------------
FROM scratch

COPY --from=builder /app/hello /
CMD ["/hello"]

Build the image:

docker build -t go-hello .

Let’s run the image:

docker run --rm --name hello go-hello

Well, I tagged the image also as aerabi/go-hello and pushed it to Docker Hub, in the case you don't want to build it yourself:

docker run --rm --name hello aerabi/go-hello

Attach a Shell to a Container

So, we have an image with no shell available. It’s not running in a container named hello. Let's try to attach a shell to it using docker exec:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Written by Mohammad-Ali A'RÂBI

Backend Engineer @ JobRad | Docker Captain | Author of Docker & Kubernetes Security | Container Security Expert

Write a response