]> git.openstreetmap.org Git - rails.git/blob - DOCKER.md
Merge pull request #6696 from mmd-osm/patch/wiki2026
[rails.git] / DOCKER.md
1 # Using Docker and Docker Compose for Development and Testing
2
3 These instructions are designed for setting up `openstreetmap-website` for development and testing using [Docker](https://www.docker.com/). This will allow you to install the OpenStreetMap application and all its dependencies in Docker images and then run them in containers, almost with a single command.
4
5 ## Install Docker
6
7 ### Windows
8
9 1. Use Docker Desktop via [docker.com Download](https://www.docker.com/products/docker-desktop/).
10
11 2. You have to enable git symlinks before cloning the repository.
12    This repository uses symbolic links that are not enabled by default on Windows git. To enable them, [turn on Developer Mode](https://windowsreport.com/windows-11-developer-mode/) on Windows and run `git config --global core.symlinks true` to enable symlinks in Git. See [this StackOverflow question](https://stackoverflow.com/questions/5917249/git-symbolic-links-in-windows) for more information.
13
14 ### Mac
15
16 - Use Docker Desktop via [docker.com Download](https://www.docker.com/products/docker-desktop/).
17 - Or [Homebrew](https://formulae.brew.sh/cask/docker).
18
19 ### Linux
20
21 Use [Docker Engine](https://docs.docker.com/engine/install/ubuntu/) with the [docker-compose-plugin](https://docs.docker.com/compose/install/linux/)
22
23 ## Clone repository
24
25 The first step is to fork/clone the repo to your local machine:
26
27 ```bash
28 git clone https://github.com/openstreetmap/openstreetmap-website.git
29 ```
30
31 Now change working directory to the `openstreetmap-website`:
32
33 ```bash
34 cd openstreetmap-website
35 ```
36
37 ## Initial Setup
38
39 ### Storage
40
41 ```bash
42 cp config/example.storage.yml config/storage.yml
43 ```
44
45 ### Database
46
47 ```bash
48 cp config/docker.database.yml config/database.yml
49 ```
50
51 ## Prepare local settings file
52
53 This is a workaround. [See issues/2185 for details](https://github.com/openstreetmap/openstreetmap-website/issues/2185#issuecomment-508676026).
54
55 ```bash
56 touch config/settings.local.yml
57 ```
58
59 **Windows users:** `touch` is not an available command in Windows so just create a `settings.local.yml` file in the `config` directory, or if you have WSL you can run `wsl touch config/settings.local.yml`.
60
61 ## Installation
62
63 To build local Docker images run from the root directory of the repository:
64
65 ```bash
66 docker compose build
67 ```
68
69 If this is your first time running or you have removed cache this will take some time to complete. Once the Docker images have finished building you can launch the images as containers.
70
71 To launch the app run:
72
73 ```bash
74 docker compose up -d
75 ```
76
77 This will launch one Docker container for each 'service' specified in `docker-compose.yml` and run them in the background. There are two options for inspecting the logs of these running containers:
78
79 - You can tail logs of a running container with a command like this: `docker compose logs -f web` or `docker compose logs -f db`.
80 - Instead of running the containers in the background with the `-d` flag, you can launch the containers in the foreground with `docker compose up`. The downside of this is that the logs of all the 'services' defined in `docker-compose.yml` will be intermingled. If you don't want this you can mix and match - for example, you can run the database in background with `docker compose up -d db` and then run the Rails app in the foreground via `docker compose up web`.
81
82 ### Migrations
83
84 Run the Rails database migrations:
85
86 ```bash
87 docker compose run --rm web bundle exec rails db:migrate
88 ```
89
90 ### Tests
91
92 Prepare the test database:
93
94 ```bash
95 docker compose run --rm web bundle exec rails db:test:prepare
96 ```
97
98 Run the test suite:
99
100 ```bash
101 docker compose run --rm web bundle exec rails test:all
102 ```
103
104 > [!TIP]
105 > If you encounter errors about missing assets, ensure your asset pipeline is correctly configured for your environment.
106 >
107 > In production, assets must be precompiled for better performance:
108 >
109 > ```bash
110 > docker compose run --rm web bundle exec rake assets:precompile
111 > ```
112 >
113 >In development, missing assets usually indicate a configuration or dependency issue.
114 > Precompiling assets in *development* will disable dynamic compilation and make debugging harder due to fingerprinted assets.
115 > To clean the assets you can run:
116 >
117 > ```bash
118 > docker compose run --rm web bundle exec rake assets:clobber
119 > ```
120
121 ### Loading an OSM extract
122
123 This installation comes with no geographic data loaded. You can either create new data using one of the editors (Potlatch 2, iD, JOSM etc) or by loading an OSM extract. Here an example for loading an OSM extract into your Docker-based OSM instance.
124
125 For example, let's download the District of Columbia from Geofabrik or [any other region](https://download.geofabrik.de):
126
127 ```bash
128 wget https://download.geofabrik.de/north-america/us/district-of-columbia-latest.osm.pbf
129 ```
130
131 You can now use Docker to load this extract into your local Docker-based OSM instance:
132
133 ```bash
134 docker compose run --rm web osmosis \
135     -verbose    \
136     --read-pbf district-of-columbia-latest.osm.pbf \
137     --log-progress \
138     --write-apidb \
139         host="db" \
140         database="openstreetmap" \
141         user="openstreetmap" \
142         validateSchemaVersion="no"
143 ```
144
145 **Windows users:** Powershell uses `` ` `` and CMD uses `^` at the end of each line, e.g.:
146
147 ```powershell
148 docker compose run --rm web osmosis `
149     -verbose    `
150     --read-pbf district-of-columbia-latest.osm.pbf `
151     --log-progress `
152     --write-apidb `
153         host="db" `
154         database="openstreetmap" `
155         user="openstreetmap" `
156         validateSchemaVersion="no"
157 ```
158
159 Once you have data loaded for Washington, DC you should be able to navigate to [`http://localhost:3000/#map=12/38.8938/-77.0146`](http://localhost:3000/#map=12/38.8938/-77.0146) to begin working with your local instance.
160
161 ### Additional Configuration
162
163 See [`CONFIGURE.md`](CONFIGURE.md) for information on how to manage users and enable OAuth for iD, JOSM etc.
164
165 ### Bash
166
167 If you want to get into a web container and run specific commands you can fire up a throwaway container to run bash in via:
168
169 ```bash
170 docker compose run --rm web bash
171 ```
172
173 Alternatively, if you want to use the already-running `web` container then you can `exec` into it via:
174
175 ```bash
176 docker compose exec web bash
177 ```
178
179 Similarly, if you want to `exec` in the db container use:
180
181 ```bash
182 docker compose exec db bash
183 ```