Problem with defining network in docker-compose

Hi all,
I try to build docker-compose file that will create DB, Ghost and phpmyadmin containers and they need to be on separate networks. I define network as normal, but when i run compose file all containers goes to the same network “backend_ghost”. I try with frontend_ghost:8080:80 and frontend_ghost:8081:2368 , but I get “error no Ip address”. Is there way to define on witch network container to expose port?

version: '3.1'

services:

  db:
    image: mariadb:10.6
    restart: always
    volumes:
       - /volume1/mysql:/etc/mysql/conf.d
    networks:
       - backend_ghost
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: ghost
      MYSQL_USER: ghost
      MYSQL_PASSWORD: ghost

  phpmyadmin:
      depends_on:   
       - db
      image: phpmyadmin
      restart: always
      ports:
       - 8081:80
      networks:
       - frontend_ghost
       - backend_ghost
      environment:
        PMA_HOST: db
        MYSQL_ROOT_PASSWORD: rootpassword        

  ghost:
    image: ghost:5-alpine
    restart: always
    volumes:
       - /volume1/data:/var/lib/ghost/content
    ports:
      - 8080:2368
    networks:
      - frontend_ghost
      - backend_ghost
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__user: ghost
      database__connection__password: ghost
      database__connection__database: ghost
      # this url value is just an example, and is likely wrong for your environment!
      url: https://example.com

networks:
    frontend_ghost:
    backend_ghost:

Thanks in advice!

What do you mean by “run compose file”?

Try how? What is it even supposed to mean?

A container can communicate with another container using the target container’s service name and the container port of the application/service inside the container.

ghost and phpmyadmin should be able to access db the way you configured it.

This docker-compose is deploy in portainer.
When i create portainer stack all containers goes to same network. What i need is this two with exposed ports to be in frontend_ghost network, but also to access DB thru backend_ghost network.

this is how what give me error with ip address:

phpmyadmin:
depends_on:
- db
image: phpmyadmin
restart: always
ports:
- frontend_ghost:8081:80
networks:
- frontend_ghost
- backend_ghost
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: rootpassword

Please format your compose file snippet to make it more readable, like I did for your first post.

What is this supposed to do?

Does the compose file even pass the schema validation when docker compose up is executed?
The correct syntax is existing-host-ip:host-port:container-port, where the existing-host-ip: part is optional.

Like I wrote: the service name is correct, it should work like this.

I have no idea how and where you get creative, but your mapping clearly shows that you are getting creative in ways that can not be found in the documentation.

Please start sharing the exact error messages you get.