novaspirit / Alpine_xfce4_noVNC

Simple and minimal Alpine Docker Image providing XFCE4 with html5 noVNC connection
91 stars 38 forks source link

How to make data persistent inbetween docker image updates? #19

Closed CountCypher closed 6 months ago

CountCypher commented 1 year ago

Hi,

first of all, thanks a lot for creating this great little docker container! I've been using the Alpine-XFCE variant of Webtop so far, but I find noVNC way more responsive than Guacamole. ;)

The only issue I'm currently facing with this container is that when I'm doing a docker compose pull followed by a docker compose up -d to apply the latest image updates, the linux environment is basically reset. For example, any configs (ssh key, ssh config) and installed tools (nano, openssh-client) are lost. So, is there any way to make at least the home directory persistent after an update? Fyi, this is my docker-compose.yml:

version: '3.3'
services:
    alpine_xfce4_novnc:
        ports:
            - '6080:6080'
        container_name: alpine-novnc
        image: novaspirit/alpine_xfce4_novnc:latest
        restart: unless-stopped
networks:
  default:
    driver: bridge
    driver_opts:
      com.docker.network.driver.mtu: 1280

Thanks in advance. :)

martadinata666 commented 1 year ago

When applications need to rebuild, for persistent data you can mount your data:

    volumes:
      - /path/to/host/data:/home/alpine/data
      - /path/to/host/data2:/home/alpine/data2

And about additional apps:

FROM novaspirit/alpine_xfce4_novnc:latest
USER root
RUN apk add --no-cache nano 
USER alpine
CountCypher commented 1 year ago

When applications need to rebuild, for persistent data you can mount your data:

    volumes:
      - /path/to/host/data:/home/alpine/data
      - /path/to/host/data2:/home/alpine/data2

@martadinata666 Thanks for the hint with the volumes. I've added now the following lines to my docker-compose.yml to make the home directory persistent on the host:

        volumes:
          - /home/maddin/docker/alpine_xfce4_novnc/home/alpine:/home/alpine

After doing a docker compose down followed by a docker compose up -d, the container log shows errors and VNC is not able to connect:

alpine-novnc  | [pulseaudio] E: [pulseaudio] core-util.c: Failed to connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
alpine-novnc  | [pulseaudio] E: [pulseaudio] core-util.c: Home directory not accessible: Permission denied
alpine-novnc  | [noVNC     ] Warning: could not find self.pem
alpine-novnc  | [Xtigervnc ] VNC authentication enabled, but no password file created.
alpine-novnc  | [audify    ] Server ready...
alpine-novnc  | [audify    ] Home directory not accessible: Permission denied
alpine-novnc  | [audify    ] ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

Seems there's some permission issue with the home directory? Any hints how I can fix this? Just a thought, because I'm not experienced with Dockerfiles: Do I maybe need to add a VOLUME instruction in there as well?

martadinata666 commented 1 year ago

don't override whole /home/alpine and set the perm to 777 to the mounted folder.

CountCypher commented 1 year ago

I've decided to make at least the directory /home/alpine/.ssh persistent. So I've edited the docker-compose.yml accordingly:

volumes:
  - /home/maddin/docker/alpine_xfce4_novnc/home/alpine/.ssh:/home/alpine/.ssh

As the .ssh directory is then initially created with the ownership of root in the container's file system, I had to change the ownership of that directory to alpine:nogroup. Afterwards writing to that directory was possible. Hope this helps somebody in the same situation. :)

homonto commented 6 months ago

don't override whole /home/alpine and set the perm to 777 to the mounted folder.

I succeeded with full home folder by: 1- creating alpine user with uid=1000 and gid=1000 (same uid and gid as my local user) 2- creating the home folder on the host with ownership 1000:1000 3- then mouting it in docker compose

so changes are here: 1) Docker file: after: build-base \ added: && addgroup -g 1000 alpine \ then modified next line to start like this: && adduser -h /home/alpine -u 1000 -G alpine...(rest is the same)

2) docker compose:

version: "3.8"
services:
  alpine:
    image: alpine
    container_name: alpine
    volumes:
      - /srv/docker/alpine/home/alpine:/home/alpine
    ports:
      - 6080:6080
      - 56780:56780
    restart: unless-stopped
CountCypher commented 6 months ago

@homonto Thanks for the hint, I'll try that. :+1: