Let’s say that you have an application that runs in Kubernetes. Now, for whatever reason, you want to test running this application on your local machine. Maybe you even want to build a local docker image and test how that works. But let’s say that your service depends on another service in Kubernetes. Now you have a problem. You can’t start your service because it won’t be able to find the other service that is living in Kubernetes. You’ll be happy to find that circumventing this problem is not very difficult.
What you want is to create a docker network, then add a mock (or perhaps even a real instance) of the service you’re dependent on and run it locally.
First you create a network:
docker network create test
Then you start the service you’re dependent on:
docker run --network=test --name nats-0 -d nats
And now finally you can run your own service:
docker run --network=test --rm my-service
And voila, you now have your local service running. Don’t forget to cleanup the network when you’re done:
docker network rm test