Reputation: 11
I'm trying to deploy a Go REST API to a local Docker container for testing. Deployment succeeds, but when I try to POST to the API, I receive the following error:
Error: connect ECONNREFUSED 127.0.0.1:8081
Here is my Dockerfile. I've already built the application locally and the binary is located at /web-admin-api:
FROM scratch
WORKDIR /web-admin-api
COPY . /web-admin-api
CMD ["/web-admin-api/application"]
EXPOSE 8081
And here's the Docker compose file:
version: "3.6"
services:
app:
container_name: web-admin-api
hostname: web-admin-api
restart: on-failure:3
environment:
GET_HOSTS_FROM: dns
ports:
- 8081:8081
networks:
- local
networks:
local:
driver: bridge
How can I get this set-up so that I can POST requests locally?
Upvotes: 1
Views: 939
Reputation: 159
Try to post with host.docker.internal
as the address instead of 127.0.0.1
You can read more about it at the documentation link 👉🏻 https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds
Upvotes: 1