Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access to localhost:8080 with docker on windows 10

When running my docker-compose-development.yaml on my computer, I can't connect to http://localhost:8080.

Also, I can run docker-compose -f docker-compose-development.yaml exec web curl http://localhost:8080 and I got a result. So it seems to not be a code problem.

What I've already done:

  • Connect directly on container IP with $ docker inspect ...
  • Try on another Windows 10 laptop (it works)
  • Change localhost to 127.0.0.1 or 0.0.0.0
  • Try another port than 8080

This is my $ docker version :

Client:
 Version:      17.11.0-ce
 API version:  1.34
 Go version:   go1.8.4
 Git commit:   1caf76c
 Built:        Mon Nov 20 18:30:11 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.11.0-ce
 API version:  1.34 (minimum version 1.12)
 Go version:   go1.8.5
 Git commit:   1caf76c
 Built:        Mon Nov 20 18:39:28 2017
 OS/Arch:      linux/amd64
 Experimental: true

This is my Dockerfile:

FROM node:9.1-alpine

RUN npm install -g nodemon


WORKDIR /opt/webserver/
COPY . /opt/webserver
RUN npm install

CMD  ["npm","run","start"]
EXPOSE 8080

RUN rm -rf /tmp/* /var/tmp/*

This is my docker-compose-development.yaml:

version: "3"

services:
  web:
    image: registry.gitlab.com/soundtrack/webapp
    ports:
      - "8080:8080"
    links:
      - database
    volumes:
      - ".:/opt/webserver:rw"
  database:
    image: mongo:3.4.10

ps command from docker-compose:

$ docker-compose -f .\docker-compose-development.yaml ps
      Name                    Command             State           Ports
--------------------------------------------------------------------------------
webapp_database_1   docker-entrypoint.sh mongod   Up      27017/tcp
webapp_web_1        npm run start                 Up      0.0.0.0:8080->8080/tcp
like image 913
Brice Avatar asked Nov 26 '17 16:11

Brice


People also ask

Can I access localhost from Docker?

Accessing the Host With the Default Bridge ModeYou just need to reference it by its Docker network IP, instead of localhost or 127.0. 0.1 . Your host's Docker IP will be shown on the inet line. Connect to this IP address from within your containers to successfully access the services running on your host.

Does Docker use port 8080?

Docker also finds ports you expose with --expose 8080 (assuming you want to expose port 8080). Docker maps all of these ports to a host port within a given epehmeral port range . You can find the configuration for these ports (usually 32768 to 61000) in /proc/sys/net/ipv4/ip_local_port_range .

How do I make my Docker talk to localhost?

docker run --network="host" Such a container will share the network stack with the docker host and from the container point of view, localhost (or 127.0. 0.1 ) will refer to the docker host. Be aware that any port opened in your docker container would be opened on the docker host.


1 Answers

I ran my container:

docker run -d -it -p 10080:80 --name=container-cool-name <container-id>

And I could see my running app with curl (inside the container)

docker exec -ti container-cool-name bash
#curl localhost:80

Here I read:

If you’re using Docker Toolbox

"docker-machine ip will tell you"

My app was correctly displaying at 192.168.99.100:10080

like image 95
hestellezg Avatar answered Oct 18 '22 09:10

hestellezg