Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memfs seems not work correctly? #27

Open
sunshine69 opened this issue Jun 1, 2022 · 0 comments
Open

memfs seems not work correctly? #27

sunshine69 opened this issue Jun 1, 2022 · 0 comments

Comments

@sunshine69
Copy link

Hi there,

I am interested to use this in my minimum docker image, basically the idea is that mount /tmp as tmpfs for the program to use. As it is minimum, there is no mount command, etc, just the app binary it self.

However from my test it seems not to use memory fs, that is after the docker container stop, I can see the file content is on the filesystem. So not sure if there is a problem with it, or the way I expect it to work is totally wrong.

Here is my snippet

package main

import (
	"fmt"
	"io/fs"
	"io/ioutil"

	"github.com/blang/vfs"
	"github.com/blang/vfs/memfs"
    u "github.com/sunshine69/golang-tools/utils"
)

func main() {
	fmt.Println("started")
	var osfs vfs.Filesystem = vfs.OS()
	err := osfs.Mkdir("/adir", 0777)
    u.CheckErr(err, "Error")
	mfs := memfs.Create()
	err = mfs.Mkdir("/tmp", 0777)
    u.CheckErr(err, "Error")
    ioutil.WriteFile("/tmp/test", []byte("hello my file"), fs.ModeAppend)
    //Seems not work, after run I can inspect the container and the file does exist. If it is in memory it should not exist
}

Dockerfile

FROM stevekieu/golang-script:20210804 AS BUILD_BASE
RUN mkdir /app && mkdir /imagetmp && chmod 1777 /imagetmp

ADD . /app/
WORKDIR /app
ENV CGO_ENABLED=0 PATH=/usr/local/go/bin:/opt/go/bin:/usr/bin:/usr/sbin:/bin:/sbin

ARG APP_VERSION
RUN go mod download golang.org/x/net
RUN go build -trimpath -ldflags="-X main.version=v1.0 -extldflags=-static -w -s" --tags "osusergo,netgo,sqlite_stat4,sqlite_foreign_keys,sqlite_json" -o minimum-docker
CMD ["/app/minimum-docker"]

FROM scratch
# the ca files is from my current ubuntu 20 /etc/ssl/certs/ca-certificates.crt - it should provide all current root certs
ADD ca-certificates.crt /etc/ssl/certs/
COPY --from=BUILD_BASE /app/minimum-docker /minimum-docker
COPY --from=BUILD_BASE /imagetmp /tmp
ENV TZ=Australia/Brisbane
ENTRYPOINT [ "/minimum-docker" ]

Build the image, and run. After run use docker inspect the container name to find the UpperDir location, and get in there, the /tmp exists a file with the content. If it is memfs, then it should not exists any file at all.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant