justxuewei / cloudreve-docker

Source code of Docker image for Cloudreve V3
https://hub.docker.com/r/xavierniu/cloudreve
MIT License
220 stars 51 forks source link

remove file volume #8

Closed geektheripper closed 4 years ago

geektheripper commented 4 years ago

"VOLUME" is used to tell docker engine to created volume directory. for example, VOLUME ["/data"] will makes docker create a volume and mount to container's "/data" (when user run "docker run" without "-v some:/data"), this feature also works on compose and swarm.

VOLUME is not a tag to show something, so it's not nessary to set file as a volume.

on the other hand, volume can't be file, becase a docker config or secret can't mount to a predefined volume

geektheripper commented 4 years ago

image

justxuewei commented 4 years ago

Hi,

In the documentation, volume can be a file, you can refer to: https://docs.docker.com/storage/volumes/

The second field is the path where the file or directory are mounted in the container.

To avoid the error you encountered, you should create those files by ‘touch’ command before running the container.

geektheripper commented 4 years ago

in swarm of compose, it is common to use secret and config to mount configuration files. but if a path is predefined as volume, we cannot mount config and secret to it.

https://docs.docker.com/engine/swarm/configs/ https://docs.docker.com/engine/swarm/secrets/

geektheripper commented 4 years ago

volume can be a file in "docker run" and "docker service create". and they did not mention file volume in the document dockerfile ref doc. but I think docker regards volume as a directory: when you run docker run -it --rm --entrypoint bash xavierniu/cloudreve -c "ls -al", you can see that docker created the directory instead do noting.

the volume in the dockerfile is used to solve the following problems:

so, when we using mysql as database, we will not mount cloudreve.db, but docker engine will, it creates a volume and mount to cloudreve.db.

geektheripper commented 4 years ago

If you are worried about the user forgetting to mount the database file, I think we should at least remove /cloudreve/conf.ini

if you let me write this Dockerfile, it will be:

FROM golang:1.14.1-alpine3.11 as builder

ARG CLOUDREVE_VERSION="3.0.0"

WORKDIR /ProjectCloudreve

RUN apk update \
    && apk add git yarn build-base gcc abuild binutils binutils-doc gcc-doc

RUN git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git

RUN cd ./Cloudreve/assets \
    && yarn install --network-timeout 1000000 \
    && yarn run build

RUN cd ./Cloudreve \
    && go get github.com/rakyll/statik \
    && statik -src=assets/build/ -include=*.html,*.js,*.json,*.css,*.png,*.svg,*.ico -f \
    && git checkout ${CLOUDREVE_VERSION} \
    && export COMMIT_SHA=$(git rev-parse --short HEAD) \
    && go build -a -o cloudreve-main -ldflags " -X 'github.com/HFO4/cloudreve/pkg/conf.BackendVersion=$CLOUDREVE_VERSION' -X 'github.com/HFO4/cloudreve/pkg/conf.LastCommit=$COMMIT_SHA'"

RUN chmod +x ./Cloudreve/cloudreve-main

FROM lsiobase/alpine:3.11

ENV PUID=1000
ENV PGID=1000
ENV TZ="Asia/Shanghai"

LABEL MAINTAINER="Xavier Niu"

WORKDIR /cloudreve

RUN echo ">>>>>> update dependencies" \
    && apk update \
    && apk add tzdata \
    && echo ">>>>>> set up timezone" \
    && cp /usr/share/zoneinfo/${TZ} /etc/localtime \
    && echo ${TZ} > /etc/timezone

VOLUME ["/cloudreve/uploads", "/downloads","/cloudreve/config", "/cloudreve/data"]

COPY --from=builder /ProjectCloudreve/Cloudreve/cloudreve-main ./

CMD ["/cloudreve/cloudreve-main" "-c" "/cloudreve/config/conf.ini"]
justxuewei commented 4 years ago

Thanks for your efforts. In my opinion, this docker image aims at those who new to docker and want to launch cloudreve on their device within one-line code. So no matter dockerfile or tutorial will be as much simple as possible. If you are pro of docker, I prefer you to fork this project and make this dockerfile fit your scenario.

geektheripper commented 4 years ago

why? my PR did not produce any breaking changes. documents don’t need to be modified, and newcomers don’t need to change the way they use this image.

justxuewei commented 4 years ago

So where conf.ini comes from? Besides, there is no way to change the path of cloudreve.db created after initialization. It must have same path with cloudreve executable.

geektheripper commented 4 years ago

user mount a config file to "/cloudreve/conf.ini", and mount a db file to "/cloudreve/cloudreve.db"

you can mount anything to any path, no matter they are defined in VOLUME or not.

justxuewei commented 4 years ago

OK, I got it! I will test it in develop branch and push unstable version to DockerHub later on. For the time being, the main branch will not be updated.

geektheripper commented 4 years ago

thanks, this will save a lot of time for swarm cluster users.

after the new image is pushed, i will create a issue and answer it, so people who have the same problem as me can get a solution.

justxuewei commented 4 years ago

You can access the latest docker image by unstable tag for now. Please feel free to let me know if you encounter any problems.