vmware / govmomi

Go library for the VMware vSphere API
Apache License 2.0
2.3k stars 910 forks source link

vcsim will not run in scratch container #2045

Closed jnovack closed 3 years ago

jnovack commented 4 years ago

In a scratch container there is no /tmp directory.

https://github.com/vmware/govmomi/blob/cfbe1d59b449be9b5378251bc6e52c65bc5e1cbd/Dockerfile.vcsim#L1-L4

The following Dockerfile fails with stat /tmp: no such file or directory

FROM golang:1.14 as build
WORKDIR /go/src/app
RUN CGO_ENABLED=0 go get -u github.com/vmware/govmomi/vcsim

FROM scratch
COPY --from=build /go/bin/vcsim /vcsim
ENTRYPOINT ["/vcsim"]

Copying over the /tmp directory (for fun), I get:

mkdir /tmp/govcsim-ha-datacenter-LocalDS_0-110559439: permission denied
dougm commented 4 years ago

vcsim uses Go's ioutil.TempDir, which uses os.TempDir - based on that, the container would need env TMPDIR set or the /tmp directory to exisit.

jnovack commented 4 years ago

Thank you dougm. Just to document for future archeologists, the following DOES work.

FROM golang:1.14 as build
WORKDIR /go/src/app
RUN CGO_ENABLED=0 go get -u github.com/vmware/govmomi/vcsim

FROM scratch
ENV TMPDIR=/tmp
COPY --from=build /tmp /tmp
COPY --from=build /go/bin/vcsim /vcsim
ENTRYPOINT ["/vcsim"]

For Docker Seamen or Docker Cadets, you cannot mkdir /tmp in the scratch container because there is no OS. Thus, you must copy it.


For those who run applications in containers as non-root, you must chown the /tmp directory on copy into the scratch container for it to work.

COPY --chown=appuser --from=build /tmp /tmp
embano1 commented 3 years ago

Is it ok to close this issue @jnovack ?

jnovack commented 3 years ago

@embano1 as soon as the PR is merged.