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.en-us.md 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. ---
  2. date: "2016-12-01T16:00:00+02:00"
  3. title: "Installation with Docker"
  4. slug: "install-with-docker"
  5. weight: 10
  6. toc: true
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "installation"
  11. name: "With Docker"
  12. weight: 10
  13. identifier: "install-with-docker"
  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. This reference setup guides users through the setup based on `docker-compose`, but the installation
  20. of `docker-compose` is out of scope of this documentation. To install `docker-compose` itself, follow
  21. the official [install instructions](https://docs.docker.com/compose/install/).
  22. ## Basics
  23. The most simple setup just creates a volume and a network and starts the `gitea/gitea:latest`
  24. image as a service. Since there is no database available, one can be initialized using SQLite3.
  25. Create a directory like `gitea` and paste the following content into a file named `docker-compose.yml`.
  26. Note that the volume should be owned by the user/group with the UID/GID specified in the config file.
  27. If you don't give the volume correct permissions, the container may not start.
  28. Also be aware that the tag `:latest` will install the current development version.
  29. For a stable release you can use `:1` or specify a certain release like `:{{< version >}}`.
  30. ```yaml
  31. version: "2"
  32. networks:
  33. gitea:
  34. external: false
  35. services:
  36. server:
  37. image: gitea/gitea:latest
  38. environment:
  39. - USER_UID=1000
  40. - USER_GID=1000
  41. restart: always
  42. networks:
  43. - gitea
  44. volumes:
  45. - ./gitea:/data
  46. ports:
  47. - "3000:3000"
  48. - "222:22"
  49. ```
  50. ## Custom port
  51. To bind the integrated openSSH daemon and the webserver on a different port, adjust
  52. the port section. It's common to just change the host port and keep the ports within
  53. the container like they are.
  54. ```diff
  55. version: "2"
  56. networks:
  57. gitea:
  58. external: false
  59. services:
  60. server:
  61. image: gitea/gitea:latest
  62. environment:
  63. - USER_UID=1000
  64. - USER_GID=1000
  65. restart: always
  66. networks:
  67. - gitea
  68. volumes:
  69. - ./gitea:/data
  70. ports:
  71. - - "3000:3000"
  72. - - "222:22"
  73. + - "8080:3000"
  74. + - "2221:22"
  75. ```
  76. ## MySQL database
  77. To start Gitea in combination with a MySQL database, apply these changes to the
  78. `docker-compose.yml` file created above.
  79. ```diff
  80. version: "2"
  81. networks:
  82. gitea:
  83. external: false
  84. services:
  85. server:
  86. image: gitea/gitea:latest
  87. environment:
  88. - USER_UID=1000
  89. - USER_GID=1000
  90. + - DB_TYPE=mysql
  91. + - DB_HOST=db:3306
  92. + - DB_NAME=gitea
  93. + - DB_USER=gitea
  94. + - DB_PASSWD=gitea
  95. restart: always
  96. networks:
  97. - gitea
  98. volumes:
  99. - ./gitea:/data
  100. ports:
  101. - "3000:3000"
  102. - "222:22"
  103. + depends_on:
  104. + - db
  105. +
  106. + db:
  107. + image: mysql:5.7
  108. + restart: always
  109. + environment:
  110. + - MYSQL_ROOT_PASSWORD=gitea
  111. + - MYSQL_USER=gitea
  112. + - MYSQL_PASSWORD=gitea
  113. + - MYSQL_DATABASE=gitea
  114. + networks:
  115. + - gitea
  116. + volumes:
  117. + - ./mysql:/var/lib/mysql
  118. ```
  119. ## PostgreSQL database
  120. To start Gitea in combination with a PostgreSQL database, apply these changes to
  121. the `docker-compose.yml` file created above.
  122. ```diff
  123. version: "2"
  124. networks:
  125. gitea:
  126. external: false
  127. services:
  128. server:
  129. image: gitea/gitea:latest
  130. environment:
  131. - USER_UID=1000
  132. - USER_GID=1000
  133. + - DB_TYPE=postgres
  134. + - DB_HOST=db:5432
  135. + - DB_NAME=gitea
  136. + - DB_USER=gitea
  137. + - DB_PASSWD=gitea
  138. restart: always
  139. networks:
  140. - gitea
  141. volumes:
  142. - ./gitea:/data
  143. ports:
  144. - "3000:3000"
  145. - "222:22"
  146. + depends_on:
  147. + - db
  148. +
  149. + db:
  150. + image: postgres:9.6
  151. + restart: always
  152. + environment:
  153. + - POSTGRES_USER=gitea
  154. + - POSTGRES_PASSWORD=gitea
  155. + - POSTGRES_DB=gitea
  156. + networks:
  157. + - gitea
  158. + volumes:
  159. + - ./postgres:/var/lib/postgresql/data
  160. ```
  161. ## Named volumes
  162. To use named volumes instead of host volumes, define and use the named volume
  163. within the `docker-compose.yml` configuration. This change will automatically
  164. create the required volume. You don't need to worry about permissions with
  165. named volumes; Docker will deal with that automatically.
  166. ```diff
  167. version: "2"
  168. networks:
  169. gitea:
  170. external: false
  171. +volumes:
  172. + gitea:
  173. + driver: local
  174. +
  175. services:
  176. server:
  177. image: gitea/gitea:latest
  178. restart: always
  179. networks:
  180. - gitea
  181. volumes:
  182. - - ./gitea:/data
  183. + - gitea:/data
  184. ports:
  185. - "3000:3000"
  186. - "222:22"
  187. ```
  188. MySQL or PostgreSQL containers will need to be created separately.
  189. ## Start
  190. To start this setup based on `docker-compose`, execute `docker-compose up -d`,
  191. to launch Gitea in the background. Using `docker-compose ps` will show if Gitea
  192. started properly. Logs can be viewed with `docker-compose logs`.
  193. To shut down the setup, execute `docker-compose down`. This will stop
  194. and kill the containers. The volumes will still exist.
  195. Notice: if using a non-3000 port on http, change app.ini to match
  196. `LOCAL_ROOT_URL = http://localhost:3000/`.
  197. ## Install
  198. After starting the Docker setup via `docker-compose`, Gitea should be available using a
  199. favorite browser to finalize the installation. Visit http://server-ip:3000 and follow the
  200. installation wizard. If the database was started with the `docker-compose` setup as
  201. documented above, please note that `db` must be used as the database hostname.
  202. ## Environments variables
  203. You can configure some of Gitea's settings via environment variables:
  204. (Default values are provided in **bold**)
  205. * `APP_NAME`: **"Gitea: Git with a cup of tea"**: Application name, used in the page title.
  206. * `RUN_MODE`: **dev**: For performance and other purposes, change this to `prod` when deployed to a production environment.
  207. * `SSH_DOMAIN`: **localhost**: Domain name of this server, used for the displayed clone URL in Gitea's UI.
  208. * `SSH_PORT`: **22**: SSH port displayed in clone URL.
  209. * `SSH_LISTEN_PORT`: **%(SSH\_PORT)s**: Port for the built-in SSH server.
  210. * `DISABLE_SSH`: **false**: Disable SSH feature when it's not available.
  211. * `HTTP_PORT`: **3000**: HTTP listen port.
  212. * `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).
  213. * `LFS_START_SERVER`: **false**: Enables git-lfs support.
  214. * `DB_TYPE`: **sqlite3**: The database type in use \[mysql, postgres, mssql, sqlite3\].
  215. * `DB_HOST`: **localhost:3306**: Database host address and port.
  216. * `DB_NAME`: **gitea**: Database name.
  217. * `DB_USER`: **root**: Database username.
  218. * `DB_PASSWD`: **"\<empty>"**: Database user password. Use \`your password\` for quoting if you use special characters in the password.
  219. * `INSTALL_LOCK`: **false**: Disallow access to the install page.
  220. * `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`.
  221. * `DISABLE_REGISTRATION`: **false**: Disable registration, after which only admin can create accounts for users.
  222. * `REQUIRE_SIGNIN_VIEW`: **false**: Enable this to force users to log in to view any page.
  223. * `USER_UID`: **1000**: The UID (Unix user ID) of the user that runs Gitea within the container. Match this to the UID of the owner of the `/data` volume if using host volumes (this is not necessary with named volumes).
  224. * `USER_GID`: **1000**: The GID (Unix group ID) of the user that runs Gitea within the container. Match this to the GID of the owner of the `/data` volume if using host volumes (this is not necessary with named volumes).
  225. # Customization
  226. Customization files described [here](https://docs.gitea.io/en-us/customizing-gitea/) should
  227. be placed in `/data/gitea` directory. If using host volumes, it's quite easy to access these
  228. files; for named volumes, this is done through another container or by direct access at
  229. `/var/lib/docker/volumes/gitea_gitea/_data`. The configuration file will be saved at
  230. `/data/gitea/conf/app.ini` after the installation.
  231. # Upgrading
  232. :exclamation::exclamation: **Make sure you have volumed data to somewhere outside Docker container** :exclamation::exclamation:
  233. To upgrade your installation to the latest release:
  234. ```
  235. # Edit `docker-compose.yml` to update the version, if you have one specified
  236. # Pull new images
  237. docker-compose pull
  238. # Start a new container, automatically removes old one
  239. docker-compose up -d
  240. ```
  241. # SSH Container Passthrough
  242. Since SSH is running inside the container, you'll have to pass SSH from the host to the
  243. container if you wish to use SSH support. If you wish to do this without running the container
  244. SSH on a non-standard port (or move your host port to a non-standard port), you can forward
  245. SSH connections destined for the container with a little extra setup.
  246. This guide assumes that you have created a user on the host called `git` which shares the same
  247. UID/GID as the container values `USER_UID`/`USER_GID`. You should also create the directory
  248. `/var/lib/gitea` on the host, owned by the `git` user and mounted in the container, e.g.
  249. ```
  250. services:
  251. server:
  252. image: gitea/gitea:latest
  253. environment:
  254. - USER_UID=1000
  255. - USER_GID=1000
  256. restart: always
  257. networks:
  258. - gitea
  259. volumes:
  260. - /var/lib/gitea:/data
  261. ports:
  262. - "3000:3000"
  263. - "127.0.0.1:2222:22"
  264. ```
  265. You can see that we're also exposing the container SSH port to port 2222 on the host, and binding this
  266. to 127.0.0.1 to prevent it being accessible external to the host machine itself.
  267. On the **host**, you should create the file `/app/gitea/gitea` with the following contents and
  268. make it executable (`chmod +x /app/gitea/gitea`):
  269. ```
  270. #!/bin/sh
  271. ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
  272. ```
  273. Your `git` user needs to have an SSH key generated:
  274. ```
  275. sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key"
  276. ```
  277. Still on the host, symlink the container `.ssh/authorized_keys` file to your git user `.ssh/authorized_keys`.
  278. This can be done on the host as the `/var/lib/gitea` directory is mounted inside the container under `/data`:
  279. ```
  280. ln -s /var/lib/gitea/git/.ssh/authorized_keys /home/git/.ssh/authorized_keys
  281. ```
  282. Then echo the `git` user SSH key into the authorized_keys file so the host can talk to the container over SSH:
  283. ```
  284. echo "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty $(cat /home/git/.ssh/id_rsa.pub)" >> /var/lib/gitea/git/.ssh/authorized_keys
  285. ```
  286. Now you should be able to use Git over SSH to your container without disrupting SSH access to the host.
  287. Please note: SSH container passthrough will work only if using opensshd in container, and will not work if
  288. `AuthorizedKeysCommand` is used in combination with setting `SSH_CREATE_AUTHORIZED_KEYS_FILE=false` to disable
  289. authorized files key generation.