diff --git a/container_usage.md b/container_usage.md index a6949e9..664230d 100644 --- a/container_usage.md +++ b/container_usage.md @@ -6,7 +6,7 @@ docker run -d --name=jikan-rest -p 8080:8080 -v ./.env:/app/.env jikanme/jikan-r - Container listens on port `8080` for http requests - By mounting your .env file on the container via `-v ./.env:/app/.env` command line option for `docker run` you can configure Jikan API. -> **Important**: You need to either mount a `.env` file on the container or specify the configuration through environment variables to make Jikan API work. Jikan API needs a MongoDB and optionally a search engine. In high load environments additionally a `redis` server is required too. The configuration should point to the correct address of these services. +> **Important**: You need to either mount a `.env` file on the container or specify the configuration through environment variables to make Jikan API work in the container. Jikan API needs a MongoDB and optionally a search engine. In high load environments additionally a `redis` server is required too. The configuration should point to the correct address of these services. > **Tip**: If you run the container on a non-default network, you can use the container names in the configuration to specify the address of services like MongoDB and TypeSense/ElasticSearch. However this is not a concern if you use `docker-compose`. @@ -16,6 +16,15 @@ docker build -t jikan-rest:nightly . docker run -d --name=jikan-rest -p 8080:8080 -v ./.env:/app/.env jikan-rest:nightly ``` +### Docker compose usage + +``` +docker-compose up +``` +Docker compose will use the `.env` file from the folder where you execute it from to load configurations for the services. If you don't have a `.env` file yet in the folder, copy the `.env.dist` file, and set the passwords. + +> **Please note**: The syntax rules of docker compose for `.env` applies here: https://docs.docker.com/compose/env-file/#syntax-rules + #### Note for Podman If you build the container image yourself with podman, the resulting image format will be OCI by default. @@ -51,6 +60,9 @@ You can read more about additional configuration options on the [Configuration W - Jikan uses RoadRunner as an application server within the container. - Both `wget` and `curl` exists in the container image. +- The script in `docker-entrypoint.php` sets safe defaults. Because of this by default the app won't behave the same way as the publicly available version of the app at [https://api.jikan.moe/v4](https://api.jikan.moe/v4). The default settings: + - No redis caching + - No search index usage (inaccurate search results) - Via Roadrunner multiple processes are running in the container, and their logs are aggregated and forwarded to `stdout`. - These processes are: - the php processes ingesting the http requests diff --git a/docker-compose.yml b/docker-compose.yml index e3e82c5..f7815e2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,14 +18,14 @@ services: APP_DEBUG: 'true' APP_ENV: local REDIS_HOST: redis - REDIS_PASSWORD: redis_password + REDIS_PASSWORD: "${REDIS_PASSWORD:-null}" DB_CONNECTION: mongodb DB_HOST: mongodb DB_DATABASE: jikan DB_PORT: 27017 DB_ADMIN: jikan - DB_USERNAME: jikan_user - DB_PASSWORD: forge + DB_USERNAME: "${DB_USERNAME}" + DB_PASSWORD: "${DB_PASSWORD}" volumes: - /etc/passwd:/etc/passwd:ro - /etc/group:/etc/group:ro @@ -56,6 +56,9 @@ services: ports: - '27017/tcp' command: --wiredTigerCacheSizeGB 1 + environment: + MONGO_INITDB_ROOT_USERNAME: "${DB_USERNAME:-root}" + MONGO_INITDB_ROOT_PASSWORD: "${DB_PASSWORD}" healthcheck: test: echo 'db.runCommand("ping").ok' | mongo mongodb://localhost:27017 --quiet interval: 30s @@ -64,7 +67,10 @@ services: redis: image: redis:7-alpine - command: redis-server --requirepass redis_password + command: + - /bin/sh + - -c + - redis-server --requirepass "$${REDIS_PASSWORD:?REDIS_PASSWORD variable is not set}" volumes: - redis-data:/data:rw ports: @@ -76,7 +82,10 @@ services: typesense: image: typesense/typesense:0.23.1 - command: -data-dir /data --api-key "typesenseapikeycomeshere" + entrypoint: /bin/sh + command: + - -c + - /opt/typesense-server --data-dir /data --api-key "$${TYPESENSE_API_KEY:?TYPESENSE_API_KEY variable is not set}" restart: no volumes: - typesense-data:/data