AzureWorld
AzureWorld

Reputation: 311

Creating a Docker Container to deploy to a prod env

I'm having some problems with building my application through Jenkins and running the container on a extrernal tomcat.

Dockerfile:

FROM node:10.16.3
RUN ls -al
WORKDIR /app
COPY /package/repo/package.json /app/package.json
RUN npm install
COPY /package/repo /app
RUN npm run build

EXPOSE 8080
CMD ["npm", "start]

npm start calls node server.js

server.js:

const express = require('express');
const app = express();
const port = 8080;

app.get('/', (req, res) => {
  res.send('Hello World!');
});


app.listen(port, () => {
  console.log(`Example app listening on port ${port}!`);
  console.log(__dirname+'/client/build/index.html');

});

app.listen(port, () => console.log(`Example app listening on port ${port}!`));

docker build -t reacttest . docker run reacttest

I'm trying to access the container using localhost:8080, however, whenever I access that port, I'm getting error not found. Is there a step I'm missing. Sorry, i'm very new to docker.

Upvotes: 0

Views: 49

Answers (2)

Heladio Amaya
Heladio Amaya

Reputation: 968

You need to map a port from your machine to the container. Use the p flag for this.

docker run reacttest -p 8080:8080

In general the syntax is:

docker run <image> -p <host port>:<container port>

You can read more in the documentation

Upvotes: 1

vanppo
vanppo

Reputation: 13

EXPOSE does not accually publish the port. You should run you container with -p flag to map ports from container to your host system. See the documents.

Upvotes: 0

Related Questions