New API Docker Compose Setup

posted
read
159 words · 1 min
contents

This note records a minimal New API deployment with Docker Compose.

Example values:

  • public domain: newapi.example.com
  • public HTTPS port: 8445
  • container app port: 3000
  • repo: https://github.com/QuantumNous/new-api.git

The domain and port are examples. Replace them with your own values.

Install Docker

If Docker is not installed yet:

Terminal window
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Check it:

Terminal window
docker version
docker compose version

Clone

Terminal window
git clone https://github.com/QuantumNous/new-api.git
cd new-api

Review the compose file before starting it:

Terminal window
vim docker-compose.yml

For a reverse-proxy setup, bind the app to localhost if the compose file allows it:

ports:
- "127.0.0.1:3000:3000"

If the upstream compose file also starts MySQL and Redis, keep their ports internal unless you have a reason to expose them.

Start

Terminal window
docker compose up -d

Check status:

Terminal window
docker compose ps
docker compose logs -f new-api
docker compose logs --tail=100 new-api

For first-time initialization, open the web page and follow the setup wizard:

https://newapi.example.com:8445

If you test without Caddy first, use:

http://198.51.100.20:3000

198.51.100.20 is a documentation IP address.

Caddy Reverse Proxy

Caddy config:

newapi.example.com:8445 {
reverse_proxy 127.0.0.1:3000
}

Reload Caddy:

Terminal window
sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddy

Open the firewall port if needed:

Terminal window
sudo nft add rule inet filter input tcp dport 8445 accept

Update

Terminal window
cd /opt/new-api
git pull
docker compose pull
docker compose up -d
docker image prune -f

If you modified tracked files directly and git pull complains, either move local changes into override files or clean the tree intentionally. Do not blindly reset --hard unless you know what you are throwing away.

Logs

Terminal window
# all services
docker compose logs -f
# selected services
docker compose logs -f new-api
docker compose logs -f mysql
docker compose logs -f redis
# foreground debug
docker compose up new-api