#Attaching to Dagger Containers during pipeline execution

1 messages · Page 1 of 1 (latest)

pearl star
#

Hi Dagger community, I apologize ahead of time if this question has been asked, I imagine it's come up before. I searched Discord for "shell into running pipeline container", "terminal in running container", but couldn't find my question/answer.

I'm coming from a Docker/Compose background where I can simply call:
docker exec -it <container> /bin/bashto shell into a container and run troubleshooting commands like ls <dir> or cat <file>. I can't find how to do this in Dagger yet.

For example, I don't see any of these containers running, I'm shocked that I get no results running the commands below while a dagger -c <function>is running. I have no clue where these containers are.

  1. docker ps
  2. ctr containers ls
  3. crictl ps

I can however, chain a Terminal() ,but it requires me to modify the Dagger module. Another option I've discovered is using dagger shell, and use the pipe, i.e. .myfunction | terminal. Is there adagger CLI command for this?

My exact use case is trying to troubleshoot the filesystem in a similar module as k3s Server function. I want to shell into the running Kubernetes k3s container and browse the filesystem. but I am unable to chain a Terminal() to the:

func (m *Kube) Server() *dagger.Service {
    return m.Container.
        AsService(dagger.ContainerAsServiceOpts{
            Args: []string{
                "sh", "-c",
                "k3s server --debug --bind-address $(ip route | grep src | awk '{print $NF}') --tls-san kubeapi --disable traefik --disable metrics-server --egress-selector-mode=disabled",
            },
            InsecureRootCapabilities: true,
            UseEntrypoint:            true,
        }).
                //doesnt work here
                //Terminal().
        WithHostname("kubeapi")
}

I get the error:
./main.go:103:3: m.Container.AsService(dagger.ContainerAsServiceOpts{…}).Terminal undefined (type *dagger.Service has no field or method Terminal)

Thank you in advance.

raw pond
#

👋 Hi there, right now we do not have the ability (afaik) to get a terminal into a running service.

digital python
#

👋 what Jason says. You can workaround it by using nsenter or similar tools to get into the process namespace.

Take into account that Dagger doesn't rely on docker to run containers, that's why you don't see anything while doing docker ps

pearl star
#

Ok thank you for the info. this was super helpful feedback. i successfully used runc list and nsenter to enter the containers.