Quantcast
Channel: Active questions tagged dockerfile - DevOps Stack Exchange
Viewing all articles
Browse latest Browse all 136

Troubles with mapping ports on a very simple Docker container

$
0
0

I'm new to Docker and following a tutorial on Udemy.com. The turtorial has me setting and running a very simple container.

Docker File

# Specify a base imageFROM node:alpine# Putting files into a specific directoryWORKDIR /usr/app# Install some dependenciesCOPY ./package.json ./RUN npm installCOPY ./ ./# Default commandCMD ["npm", "start"]

Index.js

const express = require('express');const app = express();app.get('/', (req, res) => {    res.send('Hi there');});app.listen(5000, () => {    console.log('Listening on port 5000');});

package.json

{"dependencies": {"express": "*"    },"scripts": {"start": "node index.js"    }}

I'm working on a laptop running Windows 10 Home. Using the Docker Quickstart Terminal and PowerShell.

I've edited my HOSTS file as to point localhost to 192.168.99.100, which is the ip the container gets.

I've tried hitting the server by both 192.168.99.100:5000 and localhost:5000. No matter what, when I try to access via browser(I.E. and Chrome) I get the following message:

This site can’t be reached

192.168.99.100 refused to connect.


curl http://192.168.99.100:5000

returns

curl: (7) Failed to connect to 192.168.99.100 port 5000: Connection refused


However, If I run 'docker-machine ls', I get:

tcp://192.168.99.100:2376

Why port 2376? I cannot figure out where/how this port is being assigned.

Trying the browser on that port I get a different message:

This page isn’t working

192.168.99.100 sent an invalid response.

ERR_INVALID_HTTP_RESPONSE


This would suggest(at least to me) that the server is there on that port, but not doing something right.

curl http://192.168.99.100:2376 --output -

Gives me some garbled output in the terminal, and writing it to a file gives garbled output as well. Not much, just a few garbage characters.

I suspect this is the "Hi There" message that is not being formatted correctly.

So my questions would be, am I doing something wrong in my dockerfile? Why/how is the container getting this port 2376 when i'm specifically mapping to 5000?

Any insight would be appreciated.


Viewing all articles
Browse latest Browse all 136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>