willnorris / imageproxy

A caching, resizing image proxy written in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: In the latest image I am unable to cache the images in the local disk

tech4techies opened this issue · comments

commented

I am using the
docker run -v /tmp/ttt:/tmp/imageproxy -p 8080:8080 willnorris/imageproxy -addr 0.0.0.0:8080 -cache /tmp/imageproxy this command and executing the images on port :8080 but I am unable to find any cached results in the directory path /tmp/ttt. Can I know how to fix it? I am able to cache the results with docker image with tag v0.8.0.

So there is definitely something wrong here, and there's a lot to unpack...

I can reproduce the problem with the docker builds:

  • v0.8.0 will properly read and write to the cache directory.

    docker run -v /tmp/ttt:/tmp/imageproxy -p 8080:8080 willnorris/imageproxy:v0.8.0 -addr 0.0.0.0:8080 -cache /tmp/imageproxy -verbose
    
  • v0.9.0 will read, but not write to the cache directory

    docker run -v /tmp/ttt:/tmp/imageproxy -p 8080:8080 willnorris/imageproxy:v0.9.0 -addr 0.0.0.0:8080 -cache /tmp/imageproxy -verbose
    

However, I can't reproduce the caching issue when running outside of docker... checking out and running v0.9.0 (with a change in go.mod discussed below) seems to work fine.

I can't rebuild the v0.9.0 image from source because of #190. If I reapply the replace directive in go.mod from bee1a27, then I can build the docker image, but running the image results in the following error. And finally, building the docker image from the current master builds just fine, but when you run it, it fails with this same error:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: "/app/imageproxy": stat /app/imageproxy: permission denied": unknown.

I'm not sure what would have changed to cause this to happen.

So lots to figure out. Thanks @Brahmeshwar for reporting this. I'll definitely dig into it as I have time, which will almost certainly not be as soon as I'd like, but this is now the top bug on my list... this seems to be broken pretty bad, and I'm pretty stumped as to why.

If anyone has thoughts on any of the errors above or can dig into them before I have time, that would certainly be appreciated. (especially as docker is not really my forte)

okay, I'm about ready to call the docker issue a local issue with my machine. Building and running on a different machine works fine. I still don't fully know the cause of the caching issue, but I think I can now either git bisect to find the issue. Or just accept that it seems to be working at head just fine and cut a new release.

git bisect helped me identify that this is caused by be01bc1, which completely makes sense. The "go" user inside the container doesn't have write access to the cache directory (since it's presumably owned by root).

I don't know the right long-term fix... a google search for "docker volume ownership" reveals that this is a much-discussed problem, with many of the solutions involving chowning the directory as part of building the docker image. The problem with that is that we don't know the cache directory at build time (though maybe we just standardize on /tmp/imageproxy?). For now, you could remove the USER go line in the dockerfile, and that seems to work fine (which of course means you're back to running as root)

chmoding inside the image doesn't make a difference (which makes sense). The most straightforward way seems to be to create the cache directory ahead of time, and make sure the container is running as a user which has write access to that directory.

So for example, to create the directory and run the container as your current user:

# make cache direct, and ensure it is owned by current user in case it already existed
mkdir /tmp/ttt && chown $(whoami) /tmp/ttt
docker run -u $(id -u) -v /tmp/ttt:/tmp/imageproxy -p 8080:8080 willnorris/imageproxy:v0.9.0 -addr 0.0.0.0:8080 -cache /tmp/imageproxy -verbose

So this all seems to be working as intended (from a docker permission perspective), it's just a little surprising since we changed how the container runs. I'll see about updating the docs to make this clearer.

Hi,

I've configured imageproxy with docker-compose but I am not able to see any images being served from cache.

My Config:

  imageproxy:
    image: ghcr.io/willnorris/imageproxy
    restart: "unless-stopped"
    container_name: "imageproxy"
    user: "1000"
    volumes:
      - "./data/imageproxy/cache:/tmp/imageproxy"
    env_file:
      - "./config"

My config file:

# Image Proxy

IMAGEPROXY_ADDR=0.0.0.0:8080
IMAGEPROXY_CACHE=/tmp/imageproxy

I've created the cache folder as user 1000, but its still not writeable. How can I verify that the configuration is correct? With -verbose enabled I dont see any file writing issues/exceptions.