Skip to content

Docker and Docker Compose

Dave Walker edited this page Aug 19, 2024 · 2 revisions

Overview

The Nature Recorder is available as a Docker container image. Please see the following Docker Hub repository for more information:

To run the application in Docker:

  • Create a folder to contain database, .env file and Docker Compose file
  • Create a database in that folder using the instructions in the "Database" section
  • Create a user in the database using the instructions in the "Database" section
  • Create a .env environment file containing the Flask secret key
  • Create an "Export" folder to hold exported sightings

When completed, the folder structure should look as follows:

Nature Recorder Folder

.env Environment File

  • In a local working copy of the repository, navigate to the "docker" sub-folder
  • Run the following command:
python random_secret.py
  • The output should look like this:
Error: 0
  • The script creates a .env file in the correct format in the "data" sub-folder of the working copy
  • Copy this file to the folder created in the "Overview" section, above

Create the Docker Compose file

  • The following is an example Docker Compose file that can be used to run the Nature Recorder from the published Docker image
  • It should be saved as "docker-compose.yml" in the folder containing the other files, created in the previous steps
version: "3.7"

services:
  nature-ui:
    container_name: naturerecorder
    image: davewalker5/naturerecorderpy:latest
    restart: always
    ports:
      - "8085:5000"
    volumes:
      - C:\MyApps\NatureRecorder:/var/opt/naturerecorderpy/
  • Make sure the port number, 8085 in this example, is an unused port on the local machine
  • The example assumes that the Docker Compose file, database and RapidAPI key files are in the following folder:
C:\MyApps\NatureRecorder
  • This should be changed as appropriate
  • To start the application, open a terminal window, change to the folder and run the following command:
docker compose --project-directory . up -d
  • The output should look similar to this:
C:\MyApps\NatureRecorder>docker compose --project-directory . up -d
[+] Running 2/2
 ✔ Network naturerecorder_default  Created                                                                                                                                     0.1s
 ✔ Container naturerecorder        Started
  • With the application running, browsing to the following URL should show the login page:
http://localhost:8085
  • Replace the port number, 8085, with the port used in the Docker Compose file
  • To stop the application, from the same folder run the following command:
docker compose --project-directory . down
  • The output should look similar to this:
C:\MyApps\NatureRecorder>docker compose --project-directory . down
[+] Running 2/2
 ✔ Container naturerecorder        Removed                                                                                                                                    10.6s
 ✔ Network naturerecorder_default  Removed