11

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
kevinadi
  • 13,365
  • 3
  • 33
  • 49
Brice
  • 111
  • 1
  • 1
  • 3

2 Answers2

8

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

hestellezg
  • 3,309
  • 3
  • 33
  • 37
1

Try following steps,

1 - List all the running docker containers

docker ps -a

After you run this command you should be able to view all your docker containers that are currently running and you should see a container with the name webapp_web_1 listed there.

2 - Get the IP address where your webserver container is running. To do that run the following command.

 docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" webapp_web_1

Try accessing the IP which is shown after running above command and access your running container with that IP instead of localhost.

I have answered to a simillar question related to this exact problem on Windows. Please refer it via this link to get a detailed idea on why this issue prevails.

Hope this helps you out.

Ravindu Nirmal Fernando
  • 4,272
  • 4
  • 18
  • 29