Connect host http server from Docker container that runs in WSL - docker

I have an HTTP client that runs in Docker. I need it to send request to the server that runs locally. Docker runs on Ubuntu that is WSL in Windows 10. I have the following docker-compose.yml:
version: "3.8"
test-http:
image: test-http
container_name: test-http
ports:
- "3010:3000"
environment:
- APP_PORT=3000
- APP_API_URL=http://host.docker.internal:18200
extra_hosts:
- host.docker.internal:host-gateway
As you may expect my HTTP server runs on Ubuntu via WSL on a 18200 port. When client sends request from Docker to host I get the following error:
Delete "http://host.docker.internal:18200": dial tcp 172.17.0.1:18200: connect: connection refused
How should I configure compose to make it working?

Related

Connecting to a dockerized REST JaxRS end point from within another container locally

I am attempting to connect to a rest end point of a JaxRS liferay portlet.
If I try and connect through postman using http://localhost:8078/engine-rest/process-definition
It works 200 okay.
I am attempting to connect to the same end point from within another docker container part of the same docker network, I have tried with localhost and I receive the error:
java.net.ConnectException: Connection refused (Connection refused)
I have also tried http://wasp-engine:8078, wasp-engine is the docker name of the container. Still receiving the same error.
Here are the two containers in my compose file:
wasp-engine:
image: in/digicor-engine:test
container_name: wasp-engine
ports:
- "8078:8080"
depends_on:
mysql:
condition: service_healthy
wasp:
image: in/wasp:local2
container_name: Wasp
volumes:
- liferay-document-library:/opt/liferay/data
environment:
- camundaEndPoint=http://wasp-engine:8078
ports:
- "8079:8080"
depends_on:
mysql:
condition: service_healthy
They are both connecting to the mysql fine which is part of the same docker network and referenced via:
jdbc.default.url=jdbc:mysql://mysql/liferay_test
tl;dr
Use http://wasp-engine:8080
The why
In your docker-compose the
ports: - "8078:8080"
field on wasp-engine will expose port 8080 of the docker container to your host computer on port 8078. This is what allows your postman to succeed in connecting to the container over localhost. However, once inside the docker container localhost refers to the docker container itself. This port forwarding no longer applies.
Using docker-compose you can use the name of the container to target the specific docker container. You mentioned you tried this with the URI http://wasp-engine:8078. When you access the container this way the original port is used not the forwarded port for the host machine. This means that the docker container should be targeting port 8080.
Putting it all together, the final URI should be http://wasp-engine:8080.

created apache service using docker compose but unable to access the apache(httpd) over browser

Below is my docker-compose.yml:
version: '3'
services:
proxy:
image: nginx:1.11 # this will use the latest version of 1.11.x
ports:
- '80:80' #expose 80 on host and send it to container on 80
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
web:
image: httpd #this will use httpd latest
I executed above code in an AWS EC2 instance and it created two services proxy and web as expected.
I have installed docker and docker compose on Ec2 instance and
inbound/outbound rule is "all traffic" for this instance which means port 80 is open on this instance.
However, when i try to access apache(httpd) over browser using
url htpp://Public Ip of EC2 Instance:80 then it does not open default page of apache and instead it shows message:
This site can’t be reached 54.211.70.155 refused to connect. Try: Checking the connection Checking the proxy and the firewall ERR_CONNECTION_REFUSED"

Problem with ports in docker-compose file

I am trying to link my api with my webapp but is doesn't seem to work.
I have this error
[HPM] Error occurred while trying to proxy request /users/me from
localhost:3000 to http://localhost:8080 (ECONNREFUSED)
(https://nodejs.org/api/errors.html#errors_common_system_errors)
When I try to sign in, it doesn't find the users.
Here is the contents of my docker-compose.yml file
version: '3'
services:
api:
build: ./web3-2019-api
ports:
- "8080:8080"
webapp:
build: ./web3-2019-webapp
ports:
- "3000:3000"
links:
- api
Try to connect via docker host api:8080 instead of localhost.
If you connect via localhost from webapp it expects 8080 to be running in webapp docker, but api is another docker and you should connect via api:8080. Though both are running in same machine they are virtual machines and you should connect via respective docker name within docker network

I tried to deploy gRPC (go) server in docker and expose port in local port but port bindings are not working

I tried to deploy gRPC server and mongodb in docker. After that I trying to binding docker ports to my local ports. mongodb ports binding was working fine. But, gRPC server ports are not binding my local port
ports:
- "50051:50051"
like this i tried in docker-compose.yml
docker-compose.yml
services:
auth_server:
container_name: auth_service
build: .
command: go run server.go
volumes:
- .:/go/src/auth_server
working_dir: /go/src/auth_server
ports:
- "50051:50051"
environment:
PORT: 50051
In client gRPC file I used host and port like, 0.0.0.0:50051
conn, err := grpc.Dial("0.0.0.0:50051", grpc.WithInsecure())
but it was not working. I can't find any bug, so I assume I am doing something incorrectly.
You should use 127.0.0.1:50051 when connecting from a client on the host machine, or auth_server:50051 if you are connecting from docker-compose network.
If you're running this on windows I would check the "reserved port ranges" with command
netsh interface ipv4 show excludedportrange protocol=tcp
Also see this thread on github.
If it's linux check that nothing on the host is binding on that port.

Windows 10 host wrongly uses UNIX socket instead of npipe

Docker-compose should use npipe protocol on Windows by default, but it doesn't. The following logs proves that (Win 10 pro 64 bit host):
Log 1: Failed to retrieve
information of the docker client and server host: Cannot connect to
the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon
running?
Log 2: Provider connection error Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon running?
As you can see by the logs, there was an attempt to use: unix:///var/run/docker.sock. This is a UNIX socket and not a pipe (named pipe), which Windows knows perfectly to handle.
Ok, so docker-compose has a problem with the default configuration. Let's set the pipe explicitly, to take place instead of the UNIX socket (using npipe of the long syntax):
#docker-compose.yml
version: '3.2'
services:
traefik:
image: traefik
command: --api --docker
ports:
- "80:80"
- "8080:8080"
volumes:
- type: npipe # here we are
source: ./pipe
target: /pipe/docker_engine
But guess what? We get the same UNIX socket error.
I have also tried: - ./pipe/docker_engine://./pipe/docker_engine, but failed once again.
What am I missing here?

Resources