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.en-us.md 7.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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`, the installation
  20. of `docker-compose` is out of scope of this documentation. To install `docker-compose` 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. ```yaml
  29. version: "2"
  30. networks:
  31. gitea:
  32. external: false
  33. services:
  34. server:
  35. image: gitea/gitea:latest
  36. environment:
  37. - USER_UID=1000
  38. - USER_GID=1000
  39. restart: always
  40. networks:
  41. - gitea
  42. volumes:
  43. - ./gitea:/data
  44. ports:
  45. - "3000:3000"
  46. - "222:22"
  47. ```
  48. ## Custom port
  49. To bind the integrated openSSH daemon and the webserver on a different port, adjust
  50. the port section. It's common to just change the host port and keep the ports within
  51. the container like they are.
  52. ```diff
  53. version: "2"
  54. networks:
  55. gitea:
  56. external: false
  57. services:
  58. server:
  59. image: gitea/gitea:latest
  60. environment:
  61. - USER_UID=1000
  62. - USER_GID=1000
  63. restart: always
  64. networks:
  65. - gitea
  66. volumes:
  67. - ./gitea:/data
  68. ports:
  69. - - "3000:3000"
  70. - - "222:22"
  71. + - "8080:3000"
  72. + - "2221:22"
  73. ```
  74. ## MySQL database
  75. To start Gitea in combination with a MySQL database, apply these changes to the
  76. `docker-compose.yml` file created above.
  77. ```diff
  78. version: "2"
  79. networks:
  80. gitea:
  81. external: false
  82. services:
  83. server:
  84. image: gitea/gitea:latest
  85. environment:
  86. - USER_UID=1000
  87. - USER_GID=1000
  88. restart: always
  89. networks:
  90. - gitea
  91. volumes:
  92. - ./gitea:/data
  93. ports:
  94. - "3000:3000"
  95. - "222:22"
  96. + depends_on:
  97. + - db
  98. +
  99. + db:
  100. + image: mysql:5.7
  101. + restart: always
  102. + environment:
  103. + - MYSQL_ROOT_PASSWORD=gitea
  104. + - MYSQL_USER=gitea
  105. + - MYSQL_PASSWORD=gitea
  106. + - MYSQL_DATABASE=gitea
  107. + networks:
  108. + - gitea
  109. + volumes:
  110. + - ./mysql:/var/lib/mysql
  111. ```
  112. ## PostgreSQL database
  113. To start Gitea in combination with a PostgreSQL database, apply these changes to
  114. the `docker-compose.yml` file created above.
  115. ```diff
  116. version: "2"
  117. networks:
  118. gitea:
  119. external: false
  120. services:
  121. server:
  122. image: gitea/gitea:latest
  123. environment:
  124. - USER_UID=1000
  125. - USER_GID=1000
  126. restart: always
  127. networks:
  128. - gitea
  129. volumes:
  130. - ./gitea:/data
  131. ports:
  132. - "3000:3000"
  133. - "222:22"
  134. + depends_on:
  135. + - db
  136. +
  137. + db:
  138. + image: postgres:9.6
  139. + restart: always
  140. + environment:
  141. + - POSTGRES_USER=gitea
  142. + - POSTGRES_PASSWORD=gitea
  143. + - POSTGRES_DB=gitea
  144. + networks:
  145. + - gitea
  146. + volumes:
  147. + - ./postgres:/var/lib/postgresql/data
  148. ```
  149. ## Named volumes
  150. To use named volumes instead of host volumes, define and use the named volume
  151. within the `docker-compose.yml` configuration. This change will automatically
  152. create the required volume. You don't need to worry about permissions with
  153. named volumes, Docker will deal with that automatically.
  154. ```diff
  155. version: "2"
  156. networks:
  157. gitea:
  158. external: false
  159. +volumes:
  160. + gitea:
  161. + driver: local
  162. +
  163. services:
  164. server:
  165. image: gitea/gitea:latest
  166. restart: always
  167. networks:
  168. - gitea
  169. volumes:
  170. - - ./gitea:/data
  171. + - gitea:/data
  172. ports:
  173. - "3000:3000"
  174. - "222:22"
  175. ```
  176. MySQL or PostgreSQL containers will need to be created separately.
  177. ## Start
  178. To start this setup based on `docker-compose`, execute `docker-compose up -d`,
  179. to launch Gitea in the background. Using `docker-compose ps` will show if Gitea
  180. started properly. Logs can be viewed with `docker-compose logs`.
  181. To shut down the setup, execute `docker-compose down`. This will stop
  182. and kill the containers. The volumes will still exist.
  183. Notice: if using a non-3000 port on http, change app.ini to match
  184. `LOCAL_ROOT_URL = http://localhost:3000/`.
  185. ## Install
  186. After starting the Docker setup via `docker-compose` Gitea should be available using a
  187. favorite browser to finalize the installation. Visit http://server-ip:3000 and follow the
  188. installation wizard. If the database was started with the `docker-compose` setup as
  189. documented above please note that `db` must be used as the database hostname.
  190. ## Environments variables
  191. You can configure some of Gitea's settings via environment variables:
  192. (Default values are provided in **bold**)
  193. * `APP_NAME`: **"Gitea: Git with a cup of tea"**: Application name, used in the page title.
  194. * `RUN_MODE`: **dev**: For performance and other purposes, change this to `prod` when deployed to a production environment.
  195. * `SSH_DOMAIN`: **localhost**: Domain name of this server, used for the displayed clone URL in Gitea's UI.
  196. * `SSH_PORT`: **22**: SSH port displayed in clone URL.
  197. * `DISABLE_SSH`: **false**: Disable SSH feature when it's not available.
  198. * `HTTP_PORT`: **3000**: HTTP listen port.
  199. * `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).
  200. * `DB_TYPE`: **sqlite3**: The database type in use \[mysql, postgres, mssql, sqlite3\].
  201. * `DB_HOST`: **localhost:3306**: Database host address and port.
  202. * `DB_NAME`: **gitea**: Database name.
  203. * `DB_USER`: **root**: Database username.
  204. * `DB_PASSWD`: **"<empty>"**: Database user password. Use \`your password\` for quoting if you use special characters in the password.
  205. * `INSTALL_LOCK`: **false**: Disallow access to the install page.
  206. * `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`.
  207. * `DISABLE_REGISTRATION`: **false**: Disable registration, after which only admin can create accounts for users.
  208. * `REQUIRE_SIGNIN_VIEW`: **false**: Enable this to force users to log in to view any page.
  209. * `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).
  210. * `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).
  211. # Customization
  212. Customization files described [here](https://docs.gitea.io/en-us/customizing-gitea/) should
  213. be placed in `/data/gitea` directory. If using host volumes it's quite easy to access these
  214. files; for named volumes this is done through another container or by direct access at
  215. `/var/lib/docker/volumes/gitea_gitea/_data`. The configuration file will be saved at
  216. `/data/gitea/conf/app.ini` after the installation.