Consul unable to connect to Service in docker container

When I try and service docker through docker compose, it is unable to connect to Consul.
This is my application.properties.

spring.application.name=postservice

server.port=8080
spring.data.mongodb.database=posts
spring.data.mongodb.host=${MONGODB_HOST:MongoDBPosts}
spring.data.mongodb.port=${MONGODB_PORT:27017}

management.security.enabled=false
spring.cloud.consul.host=http://consul
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.service-name=${spring.application.name}
spring.cloud.consul.discovery.instance-id=${spring.application.name}-4efb1523-76a3-f476-e6d8-452220593089

# Traefik configuration
spring.cloud.consul.discovery.tags[0]=traefik.enable=true
spring.cloud.consul.discovery.tags[1]=traefik.http.routers.${spring.application.name}.entrypoints=post
spring.cloud.consul.discovery.tags[2]=traefik.http.routers.${spring.application.name}.rule=PathPrefix('/path/')

This is my docker compose

version: "3.1"

networks:
  Pro290_network:
    external: false

services:

  Traefik:
    image: traefik:latest
    container_name: traefik
    command:
        - '--api.insecure=true'
        - '--providers.consulcatalog=true'
        - '--providers.consulcatalog.prefix=traefik'
        - '--providers.consulcatalog.endpoint.address=consul:8500'
        - '--serversTransport.insecureSkipVerify=true'
        - '--entryPoints.web.address=:80'
        - '--entryPoints.developer_api.address=:8081'
        - '--log.level=DEBUG'
    ports:
      - 80:80
      - 8081:8081
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      # - ./traefik.yaml:/etc/traefik/traefik.yaml
    networks:
      - Pro290_network
    restart: always

  MongoDBPosts:
    container_name: MongoDBPosts
    image: mongo:latest
    restart: always
    hostname: MongoDBPosts
    ports:
      - "27017:27017"
    networks:
      - Pro290_network

  PostService:
    container_name: postservice
    build: ./postservice
    image: postservice:latest
    networks:
      - Pro290_network
    ports:
      - "6001:8080"
    depends_on:
      - MongoDBPosts
      - Consul
    # labels:
    #   - "traefik.enable=true"
    #   - "traefik.http.routers.postservice.rule=Host(`postservice.Pro290_network.com`)"
    #   - "traefik.http.services.postservice.loadbalancer.server.port=8080"
    #   - "traefik.http.routers.postservice.rule=PathPrefix(`/post/`)"

  Consul:
    image: hashicorp/consul:latest
    container_name: consul
    command: "agent -dev -client=0.0.0.0"
    ports:
      - "8500:8500"
    networks:
      - Pro290_network
    labels:
      - 'traefik.enable=true'
      - 'traefik.consulcatalog.connect=true'
    restart: unless-stopped

And this is my main class

package pro290.post_service;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import okhttp3.*;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
//import okhttp3.*;

@EnableDiscoveryClient
@SpringBootApplication
@RestController
public class PostServiceApplication {

    @GetMapping(path = "/health")
    @ResponseStatus(code = HttpStatus.OK)
    public void Health() {  }
    public static void main(String[] args) throws IOException {

        SpringApplication.run(PostServiceApplication.class, args);
        //registerToConsul();
    }

}

When I’ve changed the

spring.cloud.consul.host=http://consul

to

spring.cloud.consul.host=http://localhost

My docker container for my post service shows that there is an error connecting to consul when it’s localhost, but not when it’s consul.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật