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

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