简体   繁体   中英

Docker service is unable to load on exposed port

I have created a simple DOCKERFILE and have built image "sample-image" from it inside a docker swarm, but whenever I am trying to run a container by creating docker service and exposing it on respective port but its unable to load on my browser. Kindly help

First I have initialised docker swarm and created an image "sample-image" from dockerfile, after that I created overlay network "sample-network" inside swarm and created a service to run container on it "docker service create --name sample-service -p 8010:8001 --network sample-network sample-image" . Service gets created but it couldn't loads up on a browser as I have enabled my ufw for port 8010 also.

DOCKERFILE:

FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8001
CMD [ "npm", "start" ]

server.js:

'use strict';

const express = require('express');
const PORT = 8001;
const HOST = '0.0.0.0';
const app = express();

app.get('/', (req, res) => {
  res.send('Hello world\n');
});

app.listen(PORT, HOST);

console.log(`Running on http://${HOST}:${PORT}`);

I expect my web browser to display "Hello world" on exposed port number.

Did you check the docker logs ? That should give you what is going wrong.

$ docker logs <containerid>

Could you try "curl -v http://127.0.0.1:8081 " and paste the output here please? Also, did you manipulate ufw after the service or dockerd started?

I think your listening port inside docker is 8010, and outside docker is 8001, can you try changing -p 8001:8001 ? if it works try -p 8001:8010 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM