skip to Main Content

I have the following docker-compose.yml file:

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

And network:

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

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

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:

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

It is workin fine

3

Answers


  1. Try with this compose file change image and tag

    version: '3.9'
    services:
      influxdb:
        image: influxdb:latest
        restart: always
        ports:
          - '8086:8086'
        network_mode: bridge
    
    Login or Signup to reply.
  2. you need to declare networks before you use it in services.

    see Specify custom networks and Use a pre-existing network from docker manuals.

    here is a sample config

    version: "3.9"
    services:
        result:
            image: result
            ports:
                - "8080:80"
            networks:
                - test-wp-network
    networks:
      test-wp-network:
        external:
          name: "test-wp-network"
    
    Login or Signup to reply.
  3. As you do have the network exist, Docker-compose will create a new network for any application you ran. beside what you already have.

    This network will be accessible for all the services inside your application, and not accessible for other services inside other docker applications.

    In case you need to share the access for this network, you have to define external network, usually at the end of the docker-compose.yaml like the following :

    networks:
      test-wp-network:
        external:
          name: "test-wp-network"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search