Hi, I’m having trouble connecting to my container.
I took the following steps
Docker file
FROM node:10-slim
ENV HOME=/home/app
COPY package.json package-lock.json $HOME/lib/
WORKDIR $HOME/lib
COPY . $HOME/lib
RUN npm install --silent --progress=false && npm run build && npm cache clean --force
CMD ["npm", "start"]
Build image
$ docker build -t civilizations .
Create the container
docker run -itd -e MONGO_URL='mongodb://user:password@xxxx.mlab.com:yyyyy/zzzzz' -e PORT=5000 --name civilizations -p 5000:5000 civilizations
Show logs
$ docker logs -f 17c25cf59670
> civilizations@1.0.0 start /home/app/lib
> node ./dist/server.js
'mongodb://user:password@xxxx.mlab.com:yyyyy/zzzzz 5000
Server running at: http://localhost:5000
connected to database
Enter in container
$ docker exec -it 17c25cf59670 /bin/bash
root@17c25cf59670:~/lib# wget 0.0.0.0:5000/api/enpoint/page/1/
converted 'http://0.0.0.0:5000/api/cities/page/1/' (ANSI_X3.4-1968) -> 'http://0.0.0.0:5000/api/cities/page/1/' (UTF-8)
--2018-08-18 01:42:49-- http://0.0.0.0:5000/api/endpoint/page/1/
Connecting to 0.0.0.0:5000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 96 [application/json]
Saving to: 'index.html'
index.html 100%[=======================================================================================>] 96 --.-KB/s in 0s
2018-08-18 01:42:51 (12.7 MB/s) - 'index.html' saved [96/96]
but I can not make a request in my POSTMAN client. I do not think I mapped the door correctly.
server.js
// @flow
import Hapi from 'hapi';
import { load } from 'dotenv';
import mongoose from 'mongoose';
import plugins from './plugins';
import urls from './urls';
load();
console.log(
process.env.MONGO_URL,
process.env.PORT
);
// Create a server with a host and port
const server = Hapi.server({
host: 'localhost',
port: process.env.PORT,
routes: { cors: { origin: ['*'] } },
});
mongoose.connect(
process.env.MONGO_URL,
{ useNewUrlParser: true }
);
mongoose.connection.once('open', () => {
console.log('connected to database');
});
// Start the server
async function start() {
try {
server.route(urls);
await server.register(plugins);
await server.start();
} catch (err) {
process.exit(1);
}
console.log('Server running at:', server.info.uri);
}
start();