i have use mysql for cerbose admin api but not wor...
# help
b
i have use mysql for cerbose admin api but not working storage: driver: "mysql" mysql: dsn: "root:root123@tcp(localhost:3306)/cerbos" connPool: maxLifeTime: 5m maxIdleTime: 3m maxOpen: 10 maxIdle: 5
o
Hi, The configuration looks OK to me, are you sure there is MySQL instance running in
localhost:3306
?
b
my localhost
o
How do you deploy
cerbos
and
mysql
?
b
image.png
o
I think this problem occurs because you are running
cerbos
in a container but
mysql
in the host machine.
b
yes
so how do resolve this problem
o
By adding
mysql
service into the
docker-compose.yaml
, and changing cerbos configuration to connect to it.
docker-compose.yaml
should look something like this;
Copy code
version: "3.9"
services:
  cerbos:
    container_name: cerbos
    image: <http://ghcr.io/cerbos/cerbos:latest|ghcr.io/cerbos/cerbos:latest>
    restart: always
    command: ["server", "--config=/config/conf.yaml", "--log-level=warn"]
    volumes:
      - ./cerbos/config:/config
      - ./cerbos/policies:/policies
    ports:
      - 3592:3592
      - 3593:3593

  admin-api:
    container_name: admin-api
    build: .
    environment:
      - CERBOS_HOST=cerbos
    ports:
      - 8090:8090
    depends_on:
      - cerbos

  mysql:
    container_name: mysqlstore
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      - MYSQL_DATABASE=cerbos
      - MYSQL_ROOT_PASSWORD=cerbos
      - MYSQL_USER=cerbos
      - MYSQL_PASSWORD=cerbos
    volumes:
      - ./data:/var/lib/mysql
    ports:
      - 127.0.0.1:3306:3306
and the dsn in the cerbos configuration should be like this:
cerbos:cerbos123@tcp(mysqlstore:3306)/cerbos
b
i have use this above code but showing error
o
It says
3306
port is not available. That’s probably because you have a mysql instance running on your host machine occupying the port
3306
.
b
how to use my host machine mysql with cerbose ?
o
I don’t know how it works for Windows, but using
host.docker.internal
could work. (Ex:
cerbos:cerbos123@tcp(host.docker.internal:3306)/cerbos
)
b
okay thank, i will try another way