---
title: Call Localhost on Host from Docker Container
description: There are times when we need to call "localhost" on a host from a Docker container. Here is a simple flag that allows that to happen.
date: 2021-05-11
tags: Docker, Localhost
source: https://brianchildress.co/blog/call-localhost-on-host-from-docker-container
---

# Call Localhost on Host from Docker Container

There are times when we need to call "localhost" on a host from within a Docker container. For example, when developing locally using Docker I need to call another service that is running on my host machine and not within the context of Docker, so I can't use [Docker bridge networking](https://docs.docker.com/network/bridge/). 

Recently I need to call a localhost service *from* a container running the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-docker.html). If I tried to call *http://localhost:1234* from within the AWS CLI Docker container I would be making a request to the localhost that the container is thinking about **NOT** the localhost on my machine (AKA the host).

To be able to communicate from within a container to a host service we can use the `--net="host"` flag as part of the `docker run` command. [More on Docker Host Networking](https://docs.docker.com/network/host/)

The result would look like this:

```sh
docker run --rm -it --net="host" -v ~/.aws:/root/.aws amazon/aws-cli <command>
```
