Having problem in connecting containers

I have a problem having a connection between 2 containers.
My environment:
Base machine OS “Windows 8.1” => Virtual Machine using VMWare “Windows 11” => Docker desktop on Windows 11
=> Container 1 => redis cache SERVER
=> Container 2 => .NET Console app

Currently, I have a connection string for Redis SERVER = localhost:6379 (working with Visual studio 2019)

How to connect Redis cache SERVER (Container 1) from Console Application (Container 2)?

Docker_Redis_.NET-Core-Console-App

You can never use “localhost” in a container unless you are really referring to the same container or use the same network namespace which can be the host network too. Use the built-in dns. The name of the container is also its domain name by default. In case of Docker compose, you can use the name of the compose service too.

If VSCode worked, then you probably forwarded a port from the host to the container, but that will work only from your Windows host, not from a container.

I am not clear, so How can I connect Redis SERVER from Container 2 having .NET Core Console application?

Since I don’t know .NET Core Console and I don’t know what is the name of your containers, let’s say, the redis container (or compose service) is called “redis”. Then you use redis:6379. It works if the two containers are on the same Docker network.

docker network create yournetwork
docker run --network yournetwork --name redis ...
docker run --network yournetwork --name dotnetcore ...

When you define the services in the same docker compose project, the containers will be on the same network by default so you don’t need to create a network manually.

If you need more help, you also need to share how you start the containers.

thanks for the reply. I will try this solution and still not achieve my desired result, contact you back.