Skip to content

🐞 Odd container behavior with exec / multiple withMountedDirectory #3551

Closed

Description

@plaisted

What is the issue?

The following code executes but provides unexpected logs / output. Other similar use cases error due to missing files due to same issue. This may be something very simple (haven't used golang in many years) but seems like there may be an underlying issue with the execution engine.

I would expect this code to run the ls command twice, one time showing the two mounted directories, one time showing the root output. Instead in the logs I see ls with d1 and d2 (expected), an ls with just d1 (??), and then an ls with the root fs. This causes issues if the first ls is changed to ls /example/d2 as it will error the whole pipeline due to missing path.

workdir := client.Host().Workdir()
d1, err := workdir.Read().Directory("dir1/").ID(ctx)
if err != nil {
    return err
}
d2, err := workdir.Read().Directory("dir2/").ID(ctx)
if err != nil {
    return err
}

build := client.Container().From("alpine:latest").
    WithMountedDirectory("/example/d1", d1).
    WithMountedDirectory("/example/d2", d2)

build = build.Exec(dagger.ContainerExecOpts{
    Args: []string{"ls", "/example"},
})
_, err = build.ExitCode(ctx)
if err != nil {
    return err
}
build = build.Exec(dagger.ContainerExecOpts{
    Args: []string{"ls", "/"},
})
_, err = build.ExitCode(ctx)
if err != nil {
    return err
}

I was able to get the same functionality working fine by using fs, err := build.FS().WithDirectory(d1, "/example/d1").WithDirectory(d2, "/example/d2").ID(ctx); build = build.WithFS(fs); so conceptually don't think I'm doing anything wrong.

Log output

#1 resolve image config for docker.io/library/alpine:latest
#1 DONE 0.4s

#2 mkfile /Dockerfile
#2 DONE 0.0s

#3 mkfile /main.go
#3 CACHED

#4 [internal] load metadata for docker.io/library/golang:1.18.2-alpine
#4 DONE 0.1s

#5 local://__dagger_workdir_/home/plaisted/source/OSD.PJI-Temporary/repro
#5 DONE 0.0s

#6 local://__dagger_workdir_/home/plaisted/source/OSD.PJI-Temporary/repro
#6 transferring __dagger_workdir_/home/plaisted/source/OSD.PJI-Temporary/repro: 309B done
#6 DONE 0.0s

#7 [build 1/6] FROM docker.io/library/golang:1.18.2-alpine@sha256:4795c5d21f01e0777707ada02408debe77fe31848be97cf9fa8a1462da78d949
#7 resolve docker.io/library/golang:1.18.2-alpine@sha256:4795c5d21f01e0777707ada02408debe77fe31848be97cf9fa8a1462da78d949 0.0s done
#7 DONE 0.0s

#8 [build 3/6] RUN apk add --no-cache file git
#8 CACHED

#9 [build 4/6] RUN go mod init go.dagger.io/dagger/shim/cmd
#9 CACHED

#10 [build 2/6] WORKDIR /src
#10 CACHED

#11 [build 5/6] COPY . .
#11 CACHED

#12 [build 6/6] RUN CGO_ENABLED=0 go build -o /_shim -ldflags '-s -d -w' .
#12 CACHED

#13 [stage-1 1/1] COPY --from=build /_shim /_shim
#13 CACHED

#14 mkdir /meta
#14 CACHED

#15 copy / /
#15 DONE 0.0s

#16 docker-image://docker.io/library/alpine:latest
#16 resolve docker.io/library/alpine:latest
#16 resolve docker.io/library/alpine:latest 0.1s done
#16 CACHED

#17 copy / /
#17 CACHED

#18 ls /example
#18 0.157 d1
#18 0.157 d2
#18 DONE 0.2s

#1 resolve image config for docker.io/library/alpine:latest
#1 DONE 0.5s

#4 [internal] load metadata for docker.io/library/golang:1.18.2-alpine
#4 DONE 0.4s

#19 ls /example
#19 0.172 d1
#19 DONE 0.2s

#20 ls /
#20 0.105 _shim
#20 0.105 bin
#20 0.105 dagger
#20 0.105 dev
#20 0.105 etc
#20 0.105 example
#20 0.105 home
#20 0.105 lib
#20 0.105 media
#20 0.105 mnt
#20 0.105 opt
#20 0.105 proc
#20 0.105 root
#20 0.105 run
#20 0.105 sbin
#20 0.105 srv
#20 0.105 sys
#20 0.105 tmp
#20 0.105 usr
#20 0.105 var
#20 DONE 0.1s
#0 0.148 d1
#0 0.148 d2
#18 DONE 0.2s

#1 resolve image config for docker.io/library/alpine:latest
#1 DONE 0.4s

#4 [internal] load metadata for docker.io/library/golang:1.18.2-alpine
#4 DONE 0.4s

#19 ls /example
#0 0.135 d1
#19 DONE 0.2s

#20 ls /example
#0 0.104 d1
#0 0.104 d2
#20 DONE 0.1s

Steps to reproduce

  • Mount two directories
  • Run multiple exec commands and observe logs output

Dagger version

dagger v0.3.1

OS version

Ubuntu-20.04

Activity

  1. added this to the milestone on Oct 28, 2022
  2. self-assigned this
    on Oct 30, 2022
  3. added a commit that references this issue on Oct 30, 2022
    1f287f8
  4. vito commented on Oct 30, 2022

    @vito
    Contributor

    Thanks for such a detailed issue! This should be fixed by #3602. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions