DEV Community

loading...

How to access a local server from docker

Toshiharu Nishina
A web developer for the fifth year.Rails/React/GraphQL.
Updated on ・1 min read

The Web application is built with Docker (docker-compose), and it is a way to access the API of the local environment.

I will explain with the assumption that you use Docker for Mac.

For example, if you start a local server and set the port as 3001, you can't access it from docker if you set the host as http://localhost:3001.

You can access local server if you set the host as http://docker.for.mac.localhost:3001.

From Docker for Mac ver17.06, the recommended DNS for lacalhost is docker.for.mac.localhost.

From 18.03, host.docker.internal is recommended instead of docker.for.mac.localhost as DNS for localhost.

ref.
https://docs.docker.com/v17.09/docker-for-mac/networking
https://docs.docker.com/docker-for-mac/networking

by @nishina555

Discussion (0)