https://cerbos.dev logo
#help
Title
# help
b

Balwan singh

08/22/2023, 7:12 AM
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

oguzhan

08/22/2023, 7:46 AM
Hi, The configuration looks OK to me, are you sure there is MySQL instance running in
localhost:3306
?
b

Balwan singh

08/22/2023, 8:50 AM
my localhost
o

oguzhan

08/22/2023, 9:31 AM
How do you deploy
cerbos
and
mysql
?
b

Balwan singh

08/22/2023, 9:36 AM
image.png
o

oguzhan

08/22/2023, 9:57 AM
I think this problem occurs because you are running
cerbos
in a container but
mysql
in the host machine.
b

Balwan singh

08/22/2023, 9:58 AM
yes
so how do resolve this problem
o

oguzhan

08/22/2023, 10:17 AM
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

Balwan singh

08/22/2023, 11:21 AM
i have use this above code but showing error
o

oguzhan

08/22/2023, 11:44 AM
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

Balwan singh

08/22/2023, 11:46 AM
how to use my host machine mysql with cerbose ?
o

oguzhan

08/22/2023, 12:13 PM
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

Balwan singh

08/22/2023, 12:13 PM
okay thank, i will try another way