Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to self host an Open Street Map server (using Docker)

Here are the steps needed to run a self hosted Open Street Map server (using Docker):

  1. Download desired pbf files (like south-carolina-latest.osm.pbf) from https://download.geofabrik.de or just use the following empty planet below:

    
      <?xml version='1.0' encoding='UTF-8'?>
      <osm version="0.6" generator="osmconvert 0.8.8" timestamp="2019-10-23T20:18:02Z">
        <bounds minlat="42.4276" minlon="1.412368" maxlat="42.65717" maxlon="1.787481"/>
      </osm>
    
  2. Download osmconvert from https://wiki.openstreetmap.org/wiki/Osmconvert.

  3. If you decided to use empty-planet.osm, we need to get it in pbf format, so run:

    
      osmconvert empty-planet.osm -o=data.osm.pbf
    
  4. If you decided to download some pbf files, we need to concatenate them together, so run (replacing the pbf and o5m file names where necessary):

    
      osmconvert south-carolina-latest.osm.pbf -o=south-carolina-latest.o5m
      osmconvert north-carolina-latest.osm.pbf -o=north-carolina-latest.o5m
      osmconvert south-carolina-latest.o5m north-carolina-latest.o5m -o=data.o5m
      osmconvert data.o5m -o=data.osm.pbf
    
  5. Create a Dockerfile with the following content (in the same directory where your data.osm.pbf is):

    
      FROM overv/openstreetmap-tile-server
      COPY data.osm.pbf /data.osm.pbf
      RUN /run.sh import
      VOLUME ["/var/lib/postgresql/12/main", "/var/lib/mod_tile"]
      ENTRYPOINT ["/run.sh", "run"]
    

    See https://github.com/Overv/openstreetmap-tile-server for more information about the base image used.

  6. Build the container:

    
      docker build . -t osm-self-hosted
    
  7. Run the container:

    
      docker run -p 80:80 -p 5432:5432 --name osm-self-hosted -e ALLOW_CORS=1 -d osm-self-hosted run
    

    Port 80 is for the client. Port 5432 is for the database server. ALLOW_CORS=1 will enable CORS in case your client is served from a different domain.

  8. Navigate to http://localhost in your browser. A simple example client will show the map if everything worked properly.

  9. You can connect to the database using pgAdmin with the following info:

    • Host: localhost:5432
    • Maintenance database: gis
    • User/pass is renderer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.