You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

with-docker-rootless.en-us.md 12KB

hace 2 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. ---
  2. date: "2020-02-09T20:00:00+02:00"
  3. title: "Installation with Docker (rootless)"
  4. slug: "install-with-docker-rootless"
  5. weight: 10
  6. toc: false
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "installation"
  11. name: "With Docker Rootless"
  12. weight: 10
  13. identifier: "install-with-docker-rootless"
  14. ---
  15. # Installation with Docker
  16. Gitea provides automatically updated Docker images within its Docker Hub organization. It is
  17. possible to always use the latest stable tag or to use another service that handles updating
  18. Docker images.
  19. The rootless image use Gitea internal SSH to provide Git protocol and doesn't support OpenSSH.
  20. This reference setup guides users through the setup based on `docker-compose`, but the installation
  21. of `docker-compose` is out of scope of this documentation. To install `docker-compose` itself, follow
  22. the official [install instructions](https://docs.docker.com/compose/install/).
  23. ## Basics
  24. The most simple setup just creates a volume and a network and starts the `gitea/gitea:latest-rootless`
  25. image as a service. Since there is no database available, one can be initialized using SQLite3.
  26. Create a directory for `data` and `config` then paste the following content into a file named `docker-compose.yml`.
  27. Note that the volume should be owned by the user/group with the UID/GID specified in the config file. By default Gitea in docker will use uid:1000 gid:1000. If needed you can set ownership on those folders with the command: `sudo chown 1000:1000 config/ data/`
  28. If you don't give the volume correct permissions, the container may not start.
  29. For a stable release you could use `:latest-rootless`, `:1-rootless` or specify a certain release like `:{{< version >}}-rootless`, but if you'd like to use the latest development version then `:dev-rootless` would be an appropriate tag. If you'd like to run the latest commit from a release branch you can use the `:1.x-dev-rootless` tag, where x is the minor version of Gitea. (e.g. `:1.16-dev-rootless`)
  30. ```yaml
  31. version: "2"
  32. services:
  33. server:
  34. image: gitea/gitea:{{< version >}}-rootless
  35. restart: always
  36. volumes:
  37. - ./data:/var/lib/gitea
  38. - ./config:/etc/gitea
  39. - /etc/timezone:/etc/timezone:ro
  40. - /etc/localtime:/etc/localtime:ro
  41. ports:
  42. - "3000:3000"
  43. - "2222:2222"
  44. ```
  45. ## Custom port
  46. To bind the integrated ssh and the webserver on a different port, adjust
  47. the port section. It's common to just change the host port and keep the ports within
  48. the container like they are.
  49. ```diff
  50. version: "2"
  51. services:
  52. server:
  53. image: gitea/gitea:{{< version >}}-rootless
  54. restart: always
  55. volumes:
  56. - ./data:/var/lib/gitea
  57. - ./config:/etc/gitea
  58. - /etc/timezone:/etc/timezone:ro
  59. - /etc/localtime:/etc/localtime:ro
  60. ports:
  61. - - "3000:3000"
  62. - - "2222:2222"
  63. + - "80:3000"
  64. + - "22:2222"
  65. ```
  66. ## MySQL database
  67. To start Gitea in combination with a MySQL database, apply these changes to the
  68. `docker-compose.yml` file created above.
  69. ```diff
  70. version: "2"
  71. services:
  72. server:
  73. image: gitea/gitea:{{< version >}}-rootless
  74. + environment:
  75. + - GITEA__database__DB_TYPE=mysql
  76. + - GITEA__database__HOST=db:3306
  77. + - GITEA__database__NAME=gitea
  78. + - GITEA__database__USER=gitea
  79. + - GITEA__database__PASSWD=gitea
  80. restart: always
  81. volumes:
  82. - ./data:/var/lib/gitea
  83. - ./config:/etc/gitea
  84. - /etc/timezone:/etc/timezone:ro
  85. - /etc/localtime:/etc/localtime:ro
  86. ports:
  87. - "3000:3000"
  88. - "222:22"
  89. + depends_on:
  90. + - db
  91. +
  92. + db:
  93. + image: mysql:8
  94. + restart: always
  95. + environment:
  96. + - MYSQL_ROOT_PASSWORD=gitea
  97. + - MYSQL_USER=gitea
  98. + - MYSQL_PASSWORD=gitea
  99. + - MYSQL_DATABASE=gitea
  100. + volumes:
  101. + - ./mysql:/var/lib/mysql
  102. ```
  103. ## PostgreSQL database
  104. To start Gitea in combination with a PostgreSQL database, apply these changes to
  105. the `docker-compose.yml` file created above.
  106. ```diff
  107. version: "2"
  108. services:
  109. server:
  110. image: gitea/gitea:{{< version >}}-rootless
  111. environment:
  112. + - GITEA__database__DB_TYPE=postgres
  113. + - GITEA__database__HOST=db:5432
  114. + - GITEA__database__NAME=gitea
  115. + - GITEA__database__USER=gitea
  116. + - GITEA__database__PASSWD=gitea
  117. restart: always
  118. volumes:
  119. - ./data:/var/lib/gitea
  120. - ./config:/etc/gitea
  121. - /etc/timezone:/etc/timezone:ro
  122. - /etc/localtime:/etc/localtime:ro
  123. ports:
  124. - "3000:3000"
  125. - "2222:2222"
  126. + depends_on:
  127. + - db
  128. +
  129. + db:
  130. + image: postgres:14
  131. + restart: always
  132. + environment:
  133. + - POSTGRES_USER=gitea
  134. + - POSTGRES_PASSWORD=gitea
  135. + - POSTGRES_DB=gitea
  136. + volumes:
  137. + - ./postgres:/var/lib/postgresql/data
  138. ```
  139. ## Named volumes
  140. To use named volumes instead of host volumes, define and use the named volume
  141. within the `docker-compose.yml` configuration. This change will automatically
  142. create the required volume. You don't need to worry about permissions with
  143. named volumes; Docker will deal with that automatically.
  144. ```diff
  145. version: "2"
  146. +volumes:
  147. + gitea-data:
  148. + driver: local
  149. + gitea-config:
  150. + driver: local
  151. +
  152. services:
  153. server:
  154. image: gitea/gitea:{{< version >}}-rootless
  155. restart: always
  156. volumes:
  157. - - ./data:/var/lib/gitea
  158. + - gitea-data:/var/lib/gitea
  159. - - ./config:/etc/gitea
  160. + - gitea-config:/etc/gitea
  161. - /etc/timezone:/etc/timezone:ro
  162. - /etc/localtime:/etc/localtime:ro
  163. ports:
  164. - "3000:3000"
  165. - "2222:2222"
  166. ```
  167. MySQL or PostgreSQL containers will need to be created separately.
  168. ## Custom user
  169. You can choose to use a custom user (following --user flag definition https://docs.docker.com/engine/reference/run/#user).
  170. As an example to clone the host user `git` definition use the command `id -u git` and add it to `docker-compose.yml` file:
  171. Please make sure that the mounted folders are writable by the user.
  172. ```diff
  173. version: "2"
  174. services:
  175. server:
  176. image: gitea/gitea:{{< version >}}-rootless
  177. restart: always
  178. + user: 1001
  179. volumes:
  180. - ./data:/var/lib/gitea
  181. - ./config:/etc/gitea
  182. - /etc/timezone:/etc/timezone:ro
  183. - /etc/localtime:/etc/localtime:ro
  184. ports:
  185. - "3000:3000"
  186. - "2222:2222"
  187. ```
  188. ## Start
  189. To start this setup based on `docker-compose`, execute `docker-compose up -d`,
  190. to launch Gitea in the background. Using `docker-compose ps` will show if Gitea
  191. started properly. Logs can be viewed with `docker-compose logs`.
  192. To shut down the setup, execute `docker-compose down`. This will stop
  193. and kill the containers. The volumes will still exist.
  194. Notice: if using a non-3000 port on http, change app.ini to match
  195. `LOCAL_ROOT_URL = http://localhost:3000/`.
  196. ## Install
  197. After starting the Docker setup via `docker-compose`, Gitea should be available using a
  198. favorite browser to finalize the installation. Visit http://server-ip:3000 and follow the
  199. installation wizard. If the database was started with the `docker-compose` setup as
  200. documented above, please note that `db` must be used as the database hostname.
  201. # Customization
  202. Customization files described [here](https://docs.gitea.io/en-us/customizing-gitea/) should
  203. be placed in `/var/lib/gitea/custom` directory. If using host volumes, it's quite easy to access these
  204. files; for named volumes, this is done through another container or by direct access at
  205. `/var/lib/docker/volumes/gitea_gitea/_/var_lib_gitea`. The configuration file will be saved at
  206. `/etc/gitea/app.ini` after the installation.
  207. # Upgrading
  208. :exclamation::exclamation: **Make sure you have volumed data to somewhere outside Docker container** :exclamation::exclamation:
  209. To upgrade your installation to the latest release:
  210. ```
  211. # Edit `docker-compose.yml` to update the version, if you have one specified
  212. # Pull new images
  213. docker-compose pull
  214. # Start a new container, automatically removes old one
  215. docker-compose up -d
  216. ```
  217. # Upgrading from standard image
  218. - Backup your setup
  219. - Change volume mountpoint from /data to /var/lib/gitea
  220. - If you used a custom app.ini move it to a new volume mounted to /etc/gitea
  221. - Rename folder (inside volume) gitea to custom
  222. - Edit app.ini if needed
  223. - Set START_SSH_SERVER = true
  224. - Use image gitea/gitea:{{< version >}}-rootless
  225. ## Managing Deployments With Environment Variables
  226. In addition to the environment variables above, any settings in `app.ini` can be set or overridden with an environment variable of the form: `GITEA__SECTION_NAME__KEY_NAME`. These settings are applied each time the docker container starts. Full information [here](https://github.com/go-gitea/gitea/tree/main/contrib/environment-to-ini).
  227. These environment variables can be passed to the docker container in `docker-compose.yml`. The following example will enable an smtp mail server if the required env variables `GITEA__mailer__FROM`, `GITEA__mailer__HOST`, `GITEA__mailer__PASSWD` are set on the host or in a `.env` file in the same directory as `docker-compose.yml`:
  228. ```bash
  229. ...
  230. services:
  231. server:
  232. environment:
  233. - GITEA__mailer__ENABLED=true
  234. - GITEA__mailer__FROM=${GITEA__mailer__FROM:?GITEA__mailer__FROM not set}
  235. - GITEA__mailer__MAILER_TYPE=smtp
  236. - GITEA__mailer__HOST=${GITEA__mailer__HOST:?GITEA__mailer__HOST not set}
  237. - GITEA__mailer__IS_TLS_ENABLED=true
  238. - GITEA__mailer__USER=${GITEA__mailer__USER:-apikey}
  239. - GITEA__mailer__PASSWD="""${GITEA__mailer__PASSWD:?GITEA__mailer__PASSWD not set}"""
  240. ```
  241. To set required TOKEN and SECRET values, consider using Gitea's built-in [generate utility functions](https://docs.gitea.io/en-us/command-line/#generate).
  242. # SSH Container Passthrough
  243. Since SSH is running inside the container, SSH needs to be passed through from the host to the container if SSH support is desired. One option would be to run the container SSH on a non-standard port (or moving the host port to a non-standard port). Another option which might be more straightforward is to forward SSH commands from the host to the container. This setup is explained in the following.
  244. This guide assumes that you have created a user on the host called `git` with permission to run `docker exec`, and that the Gitea container is called `gitea`. You will need to modify that user's shell to forward the commands to the `sh` executable inside the container, using `docker exec`.
  245. First, create the file `/usr/local/bin/gitea-shell` on the host, with the following contents:
  246. ```bash
  247. #!/bin/sh
  248. /usr/bin/docker exec -i --env SSH_ORIGINAL_COMMAND="$SSH_ORIGINAL_COMMAND" gitea sh "$@"
  249. ```
  250. Note that `gitea` in the docker command above is the name of the container. If you named yours differently, don't forget to change that.
  251. You should also make sure that you’ve set the permissions of the shell wrapper correctly:
  252. ```bash
  253. sudo chmod +x /usr/local/bin/gitea-shell
  254. ```
  255. Once the wrapper is in place, you can make it the shell for the `git` user:
  256. ```bash
  257. sudo usermod -s /usr/local/bin/gitea-shell git
  258. ```
  259. Now that all the SSH commands are forwarded to the container, you need to set up the SSH authentication on the host. This is done by leveraging the [SSH AuthorizedKeysCommand](https://docs.gitea.io/en-us/command-line/#keys) to match the keys against those accepted by Gitea. Add the following block to `/etc/ssh/sshd_config`, on the host:
  260. ```bash
  261. Match User git
  262. AuthorizedKeysCommandUser git
  263. AuthorizedKeysCommand /usr/bin/docker exec -i gitea /usr/local/bin/gitea keys -c /etc/gitea/app.ini -e git -u %u -t %t -k %k
  264. ```
  265. (From 1.16.0 you will not need to set the `-c /etc/gitea/app.ini` option.)
  266. All that is left to do is restart the SSH server:
  267. ```bash
  268. sudo systemctl restart sshd
  269. ```
  270. **Notes**
  271. This isn't actually using the docker SSH - it is simply using the commands around it.
  272. You could theoretically not run the internal SSH server.