1 # Using Docker and Docker Compose to run OpenStreetMap
3 Using [Docker](https://www.docker.com/) 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. You will need to install Docker and Docker Compose on your development machine:
5 - [Install Docker](https://docs.docker.com/install/)
6 - [Install Docker Compose](https://docs.docker.com/compose/install/)
8 These instructions gloss over the precise details of the dependencies and their configuration but these can be found in full detail at [INSTALL.md](INSTALL.md).
10 The first step is to fork/clone the repo to your local machine. The repository is reasonably large (~150MB) and it's unlikely that you need the full history. If you are happy to wait for it all to download, run:
12 git clone https://github.com/openstreetmap/openstreetmap-website.git
14 To clone only the most recent version (~23MB), instead use a 'shallow clone':
16 git clone --depth=1 https://github.com/openstreetmap/openstreetmap-website.git
18 Now change working directory to the `openstreetmap-website`:
20 cd openstreetmap-website
24 cp config/example.storage.yml config/storage.yml
28 cp config/docker.database.yml config/database.yml
30 ## Prepare local settings file
32 This is a workaround. [See issues/2185 for details](https://github.com/openstreetmap/openstreetmap-website/issues/2185#issuecomment-508676026).
34 touch config/settings.local.yml
38 In the root directory run:
42 Now if this is your first time running or you have removed cache this will take some time to complete. So grab tea/coffee and sit tight. Once the Docker images have finished building you can launch the images as containers.
44 To launch the app run:
48 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:
50 - You can tail logs of a running container with a command like this: `docker-compose logs -f web` or `docker-compose logs -f db`.
51 - 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`.
55 While the `db` service is running, open another terminal window and run:
57 docker-compose run --rm web rake db:migrate
61 We use Yarn to manage the Node.js modules required for the project:
63 docker-compose run --rm web rake yarn:install
65 Once these are complete you should be able to visit the app at http://localhost:3000
67 If localhost does not work, you can use the IP address of the docker-machine.
71 docker-compose run --rm web rake test:db
75 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:
77 docker-compose run --rm web bash
79 Alternatively, if you want to use the already-running `web` container then you can `exec` into it via:
81 docker-compose exec web bash
83 Similarly, if you want to `exec` in the db container use:
85 docker-compose exec db bash
87 ### Populating the database
89 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.
91 After installing but before creating any users or data, import an extract with [Osmosis](https://wiki.openstreetmap.org/wiki/Osmosis) and the `--write-apidb` task. The `web` container comes with `osmosis` pre-installed. So to populate data with a `.osm.pbf` use the following command:
93 docker-compose run --rm web osmosis \
94 --read-pbf /path/to/file.osm.pbf \
97 database="openstreetmap" \
98 user="openstreetmap" \
99 validateSchemaVersion="no"