Search code examples
dockerdocker-composegitea

Setup for volumes in docker container for gitea


I am trying to setup a gitea container and while checking the official docs, for the volumes sections, the following is defined:

 volumes:
  - ./gitea:/data
  - /etc/timezone:/etc/timezone:ro
  - /etc/localtime:/etc/localtime:ro

I know that the volumes section is used to configure DB in docker-compose but I could not find why this specific configuration is done here. Can someone explain to me what do we achieve with the lines added here in the volumes section?

To be more specific, what do we achieve with ./gitea:/data, /etc/timezone:/etc/timezone:ro and /etc/localtime:/etc/localtime:ro and why is this needed?

Thanks.


Solution

  • The volume section is a way to share files and directories between the host system and the container. With :ro the shared files can be made read-only to the container. One must understand, that a container is just a snapshot of a current build from e.g. docker hub. Whenever you delete this container, all data are deleted too. So volumes are also used to create a place for data which shall be persistent and not affected by the removal of the container.

    So what happens here: With /etc/timezone:/etc/timezone:ro the file /etc/timezone on the host system (where the docker daemon is running on) is made available under /etc/timezone (:ro means readonly) inside the container. And the same for /etc/localtime.

    Those files define the timezone used on the host. By sharing it with the container it can be used inside to recognize the systems timezone.

    Now about the line ./gitea:/data. The same way you can share files you also can share directories. In your case it's expected, that in whatever directory you are currently in, there is a folder gitea (./ means >here<). And if your execute the docker command the folder ./getea on the host is mapped to /data inside the container.

    So when you start the container, the apps inside the container will write the data to /data - and you would be also able to access those data on the host under ./gitea.