I was working with building a module which mounts an SSH socket into a container image. I noticed that calling WithUnixSocket at any point when building the container causes earlier layers to be invalidated. For example, the following module always reevaluates the apt-get install wget:
package main
import (
"context"
"dagger/apt-install-cache/internal/dagger"
)
type AptInstallCache struct{}
func (m *AptInstallCache) Container(ctx context.Context, sock *dagger.Socket) *dagger.Container {
return dag.
Container(dagger.ContainerOpts{Platform: dagger.Platform("linux/amd64")}).
From("ubuntu:24.04").
WithExec([]string{"sh", "-c", "apt-get update && apt-get install --yes wget && apt-get clean && rm -rf /var/lib/apt/lists/*"}).
WithUnixSocket("/tmp/ssh.socket", sock)
}
This seems strange to me. I'm wondering if there's something I'm missing or not understanding about how unix sockets are mounted into a container? Is there a way to build this container without invalidating the cached layers?