Docker Compose Yaml File Not Setting Resource Limits

I have a docker-compose.yml file that I call to deploy my container and it seems to work fine however when I look at the container statistics, I can’t see my resource limits being honored for CPU / RAM.

Here are the container stats from running “docker-compose up -d”:

CONTAINER ID   NAME      CPU %     MEM USAGE / LIMIT     MEM %     NET I/O        BLOCK I/O       PIDS
ee5bbad3c458   db1       0.02%     126.2MiB / 15.55GiB   0.79%     5.61MB / 7MB   184MB / 357MB   8

Below is my docker compose yaml file:

# docker-compose.yml
version: '3'
services:
  database:
    image: postgres # use latest official postgres version
    restart: always
    container_name: db1
    ports: 
      - 5432:5432
    deploy:
        resources:
            limits:
              cpus: 2
              memory: 2G 
    volumes:
      - /mnt/docker/postgresql/db1/pgdata:/var/lib/postgresql/data/

I am not getting any errors when I run

docker-compose up -d

The container is running fine but appears to not honor the resource limits. Appreciate any help on why…

I am simply trying to deploy a container using docker-compose with 2 gb of ram and 2 full cpu cores.
I am not using docker swarm or anything else. I simply want to use a docker-compose YAML file to avoid having to issue “docker run”

For example:

docker run \
 --restart unless-stopped \
 -d \
 -m 2g \
 --cpus=2 \
 --name=db1 \
 -p 3306:3306 \
 -v /mnt/docker/mysql/mysql-db1/:/var/lib/mysql \
 -e MYSQL_ROOT_PASSWORD=..xxxxxxxxxxxx \
 mysql:latest

I can not find an example of how this is done without confusing complexity or the example referencing the deploy key which appears to only be honored by swarm which I have no use for.