# Docker compose network issue

**URL:** <https://forums.docker.com/t/docker-compose-network-issue/125414>\
**Category:** General\
**Tags:** docker, docker-compose\
**Created:** [June 8, 2022, 9:44am UTC](https://forums.docker.com/t/docker-compose-network-issue/125414 "2022-06-08T09:44:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![linuxmemorywork](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/linuxmemorywork/32/32714_2.png) [@linuxmemorywork](https://forums.docker.com/u/linuxmemorywork)\
**Post date:** [June 8, 2022, 9:44am UTC](https://forums.docker.com/t/docker-compose-network-issue/125414/1 "2022-06-08T09:44:34Z")

</div>

I have the following docker-compose.yml file:

```auto
version: "3.9"
services:
    result:
        image: result
        ports:
            - "8080:80"
        networks:
            - test-wp-network

```

And network:

```auto
docker network list | grep test
a18a8c7a2764 test-wp-network bridge local

```

But when I run docker-compose up the following error is shown:

```auto
service "db" refers to undefined network test-wp-network: invalid compose project

```

Could you please clarify what is the issue and how it can be fixed?

For example, if I run it as below:

```auto
docker run --name=db -e POSTGRES_PASSWORD=mysecretpassword --network=test-wp-network postgres:9.4

```

It is working fine

---

<div class="post-metadata">

**Author:** ![linuxmemorywork](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/linuxmemorywork/32/32714_2.png) [@linuxmemorywork](https://forums.docker.com/u/linuxmemorywork)\
**Post date:** [June 8, 2022, 11:12am UTC](https://forums.docker.com/t/docker-compose-network-issue/125414/2 "2022-06-08T11:12:33Z")

</div>

I guess I found the solution it should be as below:

```auto
version: "3.9"
services:
    db:
        image: postgres:9.4
        environment:
            - POSTGRES_HOST_AUTH_METHOD=trust
        networks:
            - test-wp-network
    result:
        image: result
        ports:
            - "8080:80"
        networks:
            - test-wp-network
networks:
    test-wp-network:

```

With the declared network

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [June 10, 2022, 12:12pm UTC](https://forums.docker.com/t/docker-compose-network-issue/125414/3 "2022-06-10T12:12:52Z")

</div>

> [@linuxmemorywork](#):
>
> With the declared network

Yes, you need the definition of the network in the compose file, but docker compose will create an other network with the project name as prefix like: `<projectname>_<networkname>`. For example: `myproject_test-wp-network`. It’s fine and usually a good idea, but if you want to use the same network that you created without compose, that is an “external network”: [Docker Compose documentation: external network](https://docs.docker.com/compose/compose-file/compose-file-v2/#external-1)
