kartoza/docker-geoserver

UID/GID issue with prebuilt image in docker-compose and external volume

Hyradus opened this issue · 2 comments

What is the bug or the crash?

Hi all, first of all thanks for this amazing repo!

I am trying to integrate geoserver prebuilt image in the following docker-compose:

version: "3.9"
volumes:
  geoserver-data:
    external:
      name: ${GS_DATA_VOL}
services:
   geoserver:
    image: kartoza/geoserver:${GS_VERSION}
    container_name: geoserver
    ports:
      - 8080:8080
    volumes:
      - geoserver-data:${GEOSERVER_DATA_DIR}
    restart: on-failure
    environment:
        - GEOSERVER_DATA_DIR=${GEOSERVER_DATA_DIR}        
        - GEOSERVER_ADMIN_PASSWORD=${GEOSERVER_ADMIN_PASSWORD}
        - GEOSERVER_ADMIN_USER=${GEOSERVER_ADMIN_USER}
        - INITIAL_MEMORY=${INITIAL_MEMORY}
        - MAXIMUM_MEMORY=${MAXIMUM_MEMORY}
        - COMMUNITY_EXTENSIONS=${COMMUNITY_EXTENSIONS}
        - GEOSERVER_UID=${UID}
        - GEOSERVER_GID=${GID}
        - EXISTING_DATA_DIR=true
    healthcheck:
        test: "curl --fail --silent --write-out 'HTTP CODE : %{http_code}\n' --output /dev/null -u #${GEOSERVER_ADMIN_USER}:'${GEOSERVER_ADMIN_PASSWORD}' http://localhost:8080/geoserver/rest/about/version.xml"
        interval: 1m30s
        timeout: 10s
        retries: 3

my .env

GEOSERVER_PORT=8080

GS_DATA_VOL='geoserver-data'
GS_VERSION=2.23.0
GEOSERVER_DATA_DIR=/opt/geoserver/data_dir
GEOSERVER_ADMIN_USER=geouser
GEOSERVER_ADMIN_PASSWORD=testgeo
INITIAL_MEMORY=2G
MAXIMUM_MEMORY=8G
COMMUNITY_EXTENSIONS='cog-plugin,backup-restore-plugin'
STABLE_EXTENSIONS='importer-plugin,netcdf-plugin'
UID=1005
GID=1005

When I execute docker-compose up, it seems to run fine, but I only get a 404 page with geoserver/web folder not found.

Checking the mounted volume, the files are there but the uid/gid are 1000 (root) instead of those specificed in the env.

Manually chowning with the correct uid/gid (after docker-compose down) results with the same 404 page.

Using an internal volume works.

If i run simple docker run with the same env variables:

docker run --name "geoserver" -e GEOSERVER_ADMIN_USER=geouser -e GEOSERVER_ADMIN_PASSWORD=testgeo -e GEOSERVER_UID=1005 -e GEOSERVER_GID=1005 -p 8080:8080 -v /geoserver-data:/opt/geoserver/data_dir --rm -it kartoza/geoserver:2.23.0

everything is working, the uid/gid are correct and I can login, etc.

Then, if I stop this container and execute docker-compose up again, everything is working.

I tried different external volumes (local and network directories), but I get the same results.

So, I think I am missing something, in the docker-compose configuration because with the same env, docker-compose not works while docker run works.

EDIT1

Some additional/summary tests.

  • If the external volume is owned by a different UID than the user executing docker-compose or specificed in the env file, before executing docker-compose up the problem occur even if the external volume is rw
  • doing chown after docker-compose up, changes the ownership but still resulting in 404 page so I guess that some data is not create correctly during the first docker-compose up, or more-likely docker-compose up re-change the ownership to root (verified with ls -ll pre and post docker-compose up)
  • using docker run with or without specificing UID/GID, and with or without doing chown does change the ownership of the external volume with the UID of the user who executed docker run.
  • Creating a user with the same UID of the external volume and executin docker-compose up, does work.

Steps to reproduce the issue

  • Create simple docker-compose.yaml and .env with external volumes (see above)
  • Create docker volume
  • Docker-compose up
  • Check localhost:8080/geoserver/web - > Get 404 error
  • Check UID/GID in the mounted volume folder -> all assigned to root
  • Docker-compose down
  • docker run --name "geoserver" -e GEOSERVER_ADMIN_USER=geouser -e GEOSERVER_ADMIN_PASSWORD=testgeo -e GEOSERVER_UID=1005 -e GEOSERVER_GID=1005 -p 8080:8080 -v /geoserver-data:/opt/geoserver/data_dir --rm -it kartoza/geoserver:2.23.0
  • Check localhost:8080/geoserver/web - > Working
  • Check UID/GID in the mounted volume folder > all correct
  • Stop container
  • docker-compose up
  • Check localhost:8080/geoserver/web - > Working
  • Check UID/GID in the mounted volume folder > all correct

Versions

2.23.0

Additional context

I want to use docker-compose with prebuilt images since I am integrating it with other services and I wanted to keep as "standard" as possible

It works on my instance:
image

image

Thank for your reply and test!

It is really weird, I think I'll associate this issue with specific NFS behaviour.

I'll close it for now and re-open if I have new findings.