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

with-docker-rootless.en-us.md 9.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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: true
  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. Also be aware that the tag `:latest-rootless` will install the current development version.
  30. For a stable release you can use `:1-rootless` or specify a certain release like `:{{< version >}}-rootless`.
  31. ```yaml
  32. version: "2"
  33. services:
  34. server:
  35. image: gitea/gitea:latest-rootless
  36. restart: always
  37. volumes:
  38. - ./data:/var/lib/gitea
  39. - ./config:/etc/gitea
  40. - /etc/timezone:/etc/timezone:ro
  41. - /etc/localtime:/etc/localtime:ro
  42. ports:
  43. - "3000:3000"
  44. - "2222:2222"
  45. ```
  46. ## Custom port
  47. To bind the integrated ssh and the webserver on a different port, adjust
  48. the port section. It's common to just change the host port and keep the ports within
  49. the container like they are.
  50. ```diff
  51. version: "2"
  52. services:
  53. server:
  54. image: gitea/gitea:latest-rootless
  55. restart: always
  56. volumes:
  57. - ./data:/var/lib/gitea
  58. - ./config:/etc/gitea
  59. - /etc/timezone:/etc/timezone:ro
  60. - /etc/localtime:/etc/localtime:ro
  61. ports:
  62. - - "3000:3000"
  63. - - "2222:2222"
  64. + - "80:3000"
  65. + - "22:2222"
  66. ```
  67. ## MySQL database
  68. To start Gitea in combination with a MySQL database, apply these changes to the
  69. `docker-compose.yml` file created above.
  70. ```diff
  71. version: "2"
  72. services:
  73. server:
  74. image: gitea/gitea:latest-rootless
  75. + environment:
  76. + - DB_TYPE=mysql
  77. + - DB_HOST=db:3306
  78. + - DB_NAME=gitea
  79. + - DB_USER=gitea
  80. + - DB_PASSWD=gitea
  81. restart: always
  82. volumes:
  83. - ./data:/var/lib/gitea
  84. - ./config:/etc/gitea
  85. - /etc/timezone:/etc/timezone:ro
  86. - /etc/localtime:/etc/localtime:ro
  87. ports:
  88. - "3000:3000"
  89. - "222:22"
  90. + depends_on:
  91. + - db
  92. +
  93. + db:
  94. + image: mysql:5.7
  95. + restart: always
  96. + environment:
  97. + - MYSQL_ROOT_PASSWORD=gitea
  98. + - MYSQL_USER=gitea
  99. + - MYSQL_PASSWORD=gitea
  100. + - MYSQL_DATABASE=gitea
  101. + volumes:
  102. + - ./mysql:/var/lib/mysql
  103. ```
  104. ## PostgreSQL database
  105. To start Gitea in combination with a PostgreSQL database, apply these changes to
  106. the `docker-compose.yml` file created above.
  107. ```diff
  108. version: "2"
  109. services:
  110. server:
  111. image: gitea/gitea:latest-rootless
  112. environment:
  113. + - DB_TYPE=postgres
  114. + - DB_HOST=db:5432
  115. + - DB_NAME=gitea
  116. + - DB_USER=gitea
  117. + - DB_PASSWD=gitea
  118. restart: always
  119. volumes:
  120. - ./data:/var/lib/gitea
  121. - ./config:/etc/gitea
  122. - /etc/timezone:/etc/timezone:ro
  123. - /etc/localtime:/etc/localtime:ro
  124. ports:
  125. - "3000:3000"
  126. - "2222:2222"
  127. + depends_on:
  128. + - db
  129. +
  130. + db:
  131. + image: postgres:9.6
  132. + restart: always
  133. + environment:
  134. + - POSTGRES_USER=gitea
  135. + - POSTGRES_PASSWORD=gitea
  136. + - POSTGRES_DB=gitea
  137. + volumes:
  138. + - ./postgres:/var/lib/postgresql/data
  139. ```
  140. ## Named volumes
  141. To use named volumes instead of host volumes, define and use the named volume
  142. within the `docker-compose.yml` configuration. This change will automatically
  143. create the required volume. You don't need to worry about permissions with
  144. named volumes; Docker will deal with that automatically.
  145. ```diff
  146. version: "2"
  147. +volumes:
  148. + gitea:
  149. + driver: local
  150. +
  151. services:
  152. server:
  153. image: gitea/gitea:latest-rootless
  154. restart: always
  155. volumes:
  156. - - ./data:/var/lib/gitea
  157. + - gitea-data:/var/lib/gitea
  158. - - ./config:/etc/gitea
  159. + - gitea-config:/etc/gitea
  160. - /etc/timezone:/etc/timezone:ro
  161. - /etc/localtime:/etc/localtime:ro
  162. ports:
  163. - "3000:3000"
  164. - "2222:2222"
  165. ```
  166. MySQL or PostgreSQL containers will need to be created separately.
  167. ## Custom user
  168. You can choose to use a custom user (following --user flag definition https://docs.docker.com/engine/reference/run/#user).
  169. As an example to clone the host user `git` definition use the command `id -u git` and add it to `docker-compose.yml` file:
  170. Please make sure that the mounted folders are writable by the user.
  171. ```diff
  172. version: "2"
  173. services:
  174. server:
  175. image: gitea/gitea:latest-rootless
  176. restart: always
  177. + user: 1001
  178. volumes:
  179. - ./data:/var/lib/gitea
  180. - ./config:/etc/gitea
  181. - /etc/timezone:/etc/timezone:ro
  182. - /etc/localtime:/etc/localtime:ro
  183. ports:
  184. - "3000:3000"
  185. - "2222:2222"
  186. ```
  187. ## Start
  188. To start this setup based on `docker-compose`, execute `docker-compose up -d`,
  189. to launch Gitea in the background. Using `docker-compose ps` will show if Gitea
  190. started properly. Logs can be viewed with `docker-compose logs`.
  191. To shut down the setup, execute `docker-compose down`. This will stop
  192. and kill the containers. The volumes will still exist.
  193. Notice: if using a non-3000 port on http, change app.ini to match
  194. `LOCAL_ROOT_URL = http://localhost:3000/`.
  195. ## Install
  196. After starting the Docker setup via `docker-compose`, Gitea should be available using a
  197. favorite browser to finalize the installation. Visit http://server-ip:3000 and follow the
  198. installation wizard. If the database was started with the `docker-compose` setup as
  199. documented above, please note that `db` must be used as the database hostname.
  200. ## Environments variables
  201. You can configure some of Gitea's settings via environment variables:
  202. (Default values are provided in **bold**)
  203. * `APP_NAME`: **"Gitea: Git with a cup of tea"**: Application name, used in the page title.
  204. * `RUN_MODE`: **prod**: Application run mode, affects performance and debugging. Either "dev", "prod" or "test".
  205. * `SSH_DOMAIN`: **localhost**: Domain name of this server, used for the displayed clone URL in Gitea's UI.
  206. * `SSH_PORT`: **2222**: SSH port displayed in clone URL.
  207. * `SSH_LISTEN_PORT`: **%(SSH\_PORT)s**: Port for the built-in SSH server.
  208. * `DISABLE_SSH`: **false**: Disable SSH feature when it's not available.
  209. * `HTTP_PORT`: **3000**: HTTP listen port.
  210. * `ROOT_URL`: **""**: Overwrite the automatically generated public URL. This is useful if the internal and the external URL don't match (e.g. in Docker).
  211. * `LFS_START_SERVER`: **false**: Enables git-lfs support.
  212. * `DB_TYPE`: **sqlite3**: The database type in use \[mysql, postgres, mssql, sqlite3\].
  213. * `DB_HOST`: **localhost:3306**: Database host address and port.
  214. * `DB_NAME`: **gitea**: Database name.
  215. * `DB_USER`: **root**: Database username.
  216. * `DB_PASSWD`: **"\<empty>"**: Database user password. Use \`your password\` for quoting if you use special characters in the password.
  217. * `INSTALL_LOCK`: **false**: Disallow access to the install page.
  218. * `SECRET_KEY`: **""**: Global secret key. This should be changed. If this has a value and `INSTALL_LOCK` is empty, `INSTALL_LOCK` will automatically set to `true`.
  219. * `DISABLE_REGISTRATION`: **false**: Disable registration, after which only admin can create accounts for users.
  220. * `REQUIRE_SIGNIN_VIEW`: **false**: Enable this to force users to log in to view any page.
  221. # Customization
  222. Customization files described [here](https://docs.gitea.io/en-us/customizing-gitea/) should
  223. be placed in `/var/lib/gitea/custom` directory. If using host volumes, it's quite easy to access these
  224. files; for named volumes, this is done through another container or by direct access at
  225. `/var/lib/docker/volumes/gitea_gitea/_/var_lib_gitea`. The configuration file will be saved at
  226. `/etc/gitea/app.ini` after the installation.
  227. # Upgrading
  228. :exclamation::exclamation: **Make sure you have volumed data to somewhere outside Docker container** :exclamation::exclamation:
  229. To upgrade your installation to the latest release:
  230. ```
  231. # Edit `docker-compose.yml` to update the version, if you have one specified
  232. # Pull new images
  233. docker-compose pull
  234. # Start a new container, automatically removes old one
  235. docker-compose up -d
  236. ```
  237. # Upgrading from standard image
  238. - Backup your setup
  239. - Change volume mountpoint from /data to /var/lib/gitea
  240. - If you used a custom app.ini move it to a new volume mounted to /etc/gitea
  241. - Rename folder (inside volume) gitea to custom
  242. - Edit app.ini if needed
  243. - Set START_SSH_SERVER = true
  244. - Use image gitea/gitea:latest-rootless
  245. # SSH Container Passthrough (not tested)
  246. This should be possible by forcing `authorized_keys` generation via `gitea admin regenerate keys`.
  247. We should use directly [SSH AuthorizedKeysCommand](https://docs.gitea.io/en-us/command-line/#keys) when it will be based on internal api.