Docker - Cannot find module in docker container log - node.js

I got this error in docker desktop in docker containers logs.
I run this command in terminal of vs code
docker compose up
This is the error:
> tracking-system#1.0.0 dev /usr/src/server
> nodemon -r esm -L server.js
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node -r esm server.js server.js`
[nodemon] app crashed - waiting for file changes before starting...
Error: Cannot find module '/usr/src/server/server.js'
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
This is all my files in my project
app (folder)
node_modules (folder)
.dockerignore
.gitignore
Dockerfile
Dockerfile.prod
package.json
package-lock.json
server.js
This is my code:
server.js:
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
import passport from 'passport';
import morgan from 'morgan';
import socketio from 'socket.io';
import http from 'http';
import { success, error } from 'consola';
import { db_connection } from './app/config';
const app = express();
const server = http.createServer(app);
const io = socketio(server);
const PORT = process.env.SERVER_PORT || 8861;
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
credentials: true,
};
app.use(cors(corsOptions));
app.use(express.json());
app.use(passport.initialize());
app.use(morgan('dev'));
import passport_init from './app/middleware/passport';
import userRoute from './app/routes/user.route';
import authRoute from './app/routes/auth.route';
passport_init(passport);
app.use('/api/users', userRoute);
app.use('/api/auth', authRoute);
const startDatabase = async () => {
try {
await mongoose.connect(db_connection, {
useNewUrlParser: true,
useFindAndModify: true,
useUnifiedTopology: true,
useFindAndModify: false,
dbName: 'tracking-system',
});
success({
message: `Successfully connected with the database on ${db_connection}`,
badge: true,
});
} catch (err) {
error({
message: `Unable to connected with the database ${err}`,
badge: true,
});
setTimeout(startDatabase, 5000);
}
};
startDatabase();
server.listen(PORT, () => {
success({ message: `Server started on PORT ${PORT}`, badge: true });
});
io.on('connection', socket => {
console.log(`Connected: ${socket.id}`)
socket.on('disconnect', () => {
console.log(`Disconnected: ${socket.id}`)
})
socket.on('update-worksheet', function () {
io.sockets.emit('update-landing-page')
})
})
Dockerfile:
FROM node:lts-buster
WORKDIR /project/server
COPY ./server/package*.json ./
RUN npm install
COPY ./.env ../.env
CMD ["npm", "run", "dev"]
package.json:
{
"name": "tracking-system",
"version": "1.0.0",
"description": "for tracking device repairation",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node -r esm server.js",
"dev": "nodemon -r esm -L server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "5.0.1",
"colors": "^1.4.0",
"consola": "^2.15.3",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"esm": "^3.2.25",
"express": "^4.17.1",
"express-session": "^1.17.2",
"http-server": "^0.12.3",
"jsonwebtoken": "^8.5.1",
"moment-timezone": "^0.5.33",
"mongoose": "^5.13.5",
"morgan": "^1.10.0",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"socket.io": "^4.1.3"
},
"devDependencies": {
"nodemon": "^2.0.7"
}
}
Thanks if you can help. My friend can't help.
This is my docker version:
Docker version 20.10.7, build f0df350
This is my docker info:
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
compose: Docker Compose (Docker Inc., v2.0.0-beta.6)
scan: Docker Scan (Docker Inc., v0.8.0)
Server:
Containers: 4
Running: 4
Paused: 0
Stopped: 0
Images: 4
Server Version: 20.10.7
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 5.10.16.3-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 12.43GiB
Name: docker-desktop
ID: LASO:BRSF:IIDP:3W6O:4TRG:CRIF:H54G:WWN3:EFAP:6NLU:MMSS:OHG5
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
I use windows 10 pro

In the line 3 in your Dockerfile you only copy the package.json of your project but never copy the source code of your app.
FROM node:lts-buster
WORKDIR /project/server
COPY ./server/package*.json ./
RUN npm install
COPY ./.env ../.env
CMD ["npm", "run", "dev"]
So, you can try with this Dockerfile (i changed the workdir and now it copying all source code):
FROM node:lts-buster
WORKDIR /usr/src/server
COPY . .
RUN npm install
CMD ["npm", "run", "dev"]
Reference: Dockerizing a Node.js web app

Related

Docker & Nodejs - ReferenceError: TextEncoder is not defined

I'm encountering the following error while trying to launch my docker container:
Error:
server_1 | /usr/src/app/node_modules/whatwg-url/lib/encoding.js:2
server_1 | const utf8Encoder = new TextEncoder();
server_1 | ^
server_1 |
server_1 | ReferenceError: TextEncoder is not defined
Dockerfile:
FROM --platform=linux/amd64 node:current-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "prod"]
docker-compose.yml:
version: '3'
services:
server:
build:
context: ./server
ports:
- "3008:3002"
environment:
API_PORT: "3002"
DB_HOST: "192.168.1.211"
DB_PORT: "27018"
DB_NAME: "tutorialitems"
restart: always
index.js file:
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
app.use(cors());
app.use(bodyParser({ limit: '50mb' }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
//DB
const db = require('./models');
const dbConfig = require('./config/db.config');
try {
db.mongoose.connect(`mongodb://${dbConfig.HOST}:${dbConfig.PORT}/${dbConfig.DB}`, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
console.log('DB Connected!');
} catch (error) {
console.log('Cannot connect to DB...', error);
process.exit();
}
//Routes
require('./routes/crud.routes')(app);
app.get('/', (req, res) => {
res.json("Server is Running")
});
app.listen(process.env.API_PORT, () => {
console.log(`Server is listening on port ${process.env.API_PORT}`)
});
What I tried (but unsuccessfully):
I updated the following file: node_modules > whatwg-url > lib > encoding.js from
Initial:
"use strict";
const utf8Encoder = new TextEncoder();
const utf8Decoder = new TextDecoder("utf-8", { ignoreBOM: true });
to Updated:
const util = require("util");
const utf8Decoder = new util.TextEncoder("utf-8", { ignoreBOM: true });
package.json:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon index.js",
"prod": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.2",
"mongoose": "^6.1.5",
"nodemon": "^2.0.15"
}
}
But when I run my docker-compose, I still have the same error.
Anyone has an idea?
Thks
Mongoose v6.1.5 is working with Node 17.3.0.
Package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon index.js",
"prod": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.2",
"mongoose": "^6.1.5",
"nodemon": "^2.0.15"
}
}
After updating my package.json with the Mongoose 6.1.5 version, and my Dockerfile as following:
FROM --platform=linux/amd64 node:17.3.0
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "prod"]
I run the following docker-compose commands:
docker-compose pull
docker-compose build
docker-compose up
And now it's working. It seems that docker-compose up was still using the previously build version... thus, it was not working...
package.json:
"mongoose": "^6.2.7"
DockerFile:
FROM node:17-slim
I was getting the same error, when I set the versions as above (node:16-slim to 17-slim), my problem went away. Thanks..

Dockerized Node API using official Node image

The below code runs the server.js without installing the node modules in the package.json, so it run into an error Error: Cannot find module 'koa'. Is it possible to install node modules on the prebuilt Docker Node image (https://github.com/nodejs/docker-node) using docker-compose?
I tried command: "yarn install && yarn start" in docker-compose.yml, but that's not valid.
docker-compose.yml
version: "3.8"
services:
my-api:
image: node:16-alpine
user: node
working_dir: /home/node/app
volumes:
- ./:/home/node/app
- /home/node/app/node_modules
command: "yarn start"
expose:
- 5000
ports:
- 5000:5000
package.json
{
"name": "my-api",
"private": true,
"scripts": {
"install": "yarn install",
"start": "node server.js"
},
"main": "server.js",
"dependencies": {
"koa": "^2.13.0",
"#koa/cors": "^3.1.0",
"koa-bodyparser": "^4.3.0",
"koa-logger": "^3.2.1",
"koa-router": "^9.0.0"
}
}
server.js
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const logger = require('koa-logger');
const Router = require('koa-router');
const cors = require('#koa/cors');
console.log('server ready');

SyntaxError: Unexpected token '<' when dockerizing react app

I have a react project with Webpack which I'm trying to dockerize it following this article.
Dockerfile:
FROM node:12.14.1
RUN npm install webpack -g
WORKDIR /tmp
COPY package.json /tmp/
RUN npm config set registry http://registry.npmjs.org/ && npm install
WORKDIR /usr/app
COPY . /usr/app/
RUN cp -a /tmp/node_modules /usr/app/
RUN webpack
ENV NODE_ENV=production
ENV PORT=4000
CMD [ "/usr/local/bin/node", "--experimental-modules", "./src/index.js" ]
EXPOSE 4000
docker-compose.yml:
ex_dashboard:
build: .
ports:
- "80:4000"
volumes:
- .:/usr/app/:rw
environment:
- NODE_ENV=dev
command: >
sh -c '
if test -d node_modules;
then
echo node_modules_exists ;
else
cp -a /tmp/node_modules /usr/app/dashboard;
fi &&
npm install &&
/usr/local/bin/node --experimental-modules ./src/index.js
'
When I run docker-compose up, everything goes well until I encounter this error:
ex_dashboard_1 | (node:18) ExperimentalWarning: The ESM module loader is experimental.
ex_dashboard_1 | file:///usr/app/src/index.js:9
ex_dashboard_1 | <Provider store={store}>
ex_dashboard_1 | ^
ex_dashboard_1 |
ex_dashboard_1 | SyntaxError: Unexpected token '<'
ex_dashboard_1 | at Loader.moduleStrategy (internal/modules/esm/translators.js:66:18)
ex_dashboard_1 | at async link (internal/modules/esm/module_job.js:37:21)
The whole project works well if I just run it by npm start or build it by npm run build. But I don't know why this happens in docker container.
Here is package.json:
{
"name": "explore_dashboard",
"version": "1.0.0",
"description": "A dashboard for the Explore project",
"main": "index.js",
"type": "module",
"scripts": {
"start": "cross-env NODE_ENV=development webpack-dev-server --hot",
"build": "cross-env NODE_ENV=production webpack",
"lint": "eslint ./src",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gitlab.basalam.dev/data/explore_dashboard.git"
},
"author": "Gh.Sherafati",
"license": "ISC",
"resolve": {
"alias": {
"react-dom": "#hot-loader/react-dom"
}
},
"devDependencies": {
"#babel/core": "^7.8.4",
"#babel/plugin-transform-runtime": "^7.8.3",
"#babel/preset-env": "^7.8.4",
"#babel/preset-react": "^7.8.3",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"cross-env": "^7.0.0",
"css-loader": "^3.4.2",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-loader": "^3.0.3",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.18.0",
"eslint-plugin-react-hooks": "^1.7.0",
"html-webpack-plugin": "^3.2.0",
"node-sass": "^4.13.1",
"sass-loader": "^8.0.2",
"style-loader": "^1.1.3",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.2"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.27",
"#fortawesome/free-solid-svg-icons": "^5.12.1",
"#fortawesome/react-fontawesome": "^0.1.8",
"#hot-loader/react-dom": "^16.11.0",
"#types/react": "^16.9.19",
"axios": "^0.19.2",
"react": "^16.12.0",
"react-beautiful-dnd": "^12.2.0",
"react-dom": "^16.12.0",
"react-hot-loader": "^4.12.19",
"react-redux": "^7.1.3",
"redux": "^4.0.5",
"redux-saga": "^1.1.3"
}
}
And webpack.config.js:
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { env } = process;
module.exports = {
entry: './src/index.js',
mode: env.NODE_ENV,
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader'],
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
'css-loader',
// Compiles Sass to CSS
'sass-loader',
],
},
],
},
resolve: {
extensions: ['*', '.js', '.jsx'],
},
output: {
path: path.join(__dirname, '/build'),
publicPath: '/',
filename: 'bundle.js',
},
plugins: [
new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(env.NODE_ENV) }),
new HtmlWebpackPlugin({
template: path.resolve('./src/index.html'),
}),
],
devServer: {
contentBase: './build',
hot: true,
},
devtool: env.NODE_ENV === 'development' ? 'cheap-module-eval-source-map' : undefined,
};
Also index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import store from './redux/store';
import App from './components/App';
import './scss/main.scss';
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('app'),
);
module.hot.accept();
The --experimental-modules flag can be used to enable support for ECMAScript modules (ES modules).
option 1
CMD ["sh", "-c", "exec node --experimental-modules index.js"]
option 2
CMD exec node --experimental-modules index.js
Full Docs:
In your docker-compose.yml file, delete the volumes: and the rather long-winded command:.
The important thing that’s going on here is that your index.js file actually includes JSX constructs that React uses; it’s not plain Javascript and node can’t run it directly. In your Dockerfile you RUN webpack, which transpiles this into plain Javascript. The volumes: overwrite all of this with whatever content is on your local system; that does not include a transpilation step, so you don’t have valid Javascript for Node to run.
(It might work to put an explicit call to webpack in that command:. This assumes your host and container node_modules are compatible, and it is literally duplicating everything the Dockerfile does to build the image in the docker-compose.yml file.)
Nothing stops you from installing Node on your host system (if you don’t already have it), doing live development using the Webpack dev server, and then using Docker for a final packaging step. That’s probably much more convenient than introducing an isolation system like Docker and then trying to work around all of its features to emulate a local development setup.
Finally I've solve the issue by using nginx and running the build version in the container getting help from this great article.
The new Dockerfile and docker-compose.yml follows:
Dockerfile:
FROM node:12.14.1 as build
WORKDIR /app
COPY . /app
ENV PATH /app/node_modules/.bin:$PATH
RUN npm install
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
docker-compose.yml:
version: "3"
services:
explore_dashboard:
container_name: explore_dashboard
build:
context: .
dockerfile:
Dockerfile
ports:
- "8081:80"
nginx.conf:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Now I'm able to run the app on http://127.0.0.1:8081/ running:
docker-compose up

Unable to debug a nodejs app inside of docker

I am trying my hands on debugging a Nodejs app from inside of Docker using Nodemon.
I can debug my app with Nodemon without Docker using Visual Studio Code's Auto Attach feature.
But when I build my docker image and start the container via npm run dev:docker:debug I get following log but debugger is not attached. It might be something with the volume but I am not able to figure it out...
Successfully built 857d9da57565
Successfully tagged app:dev
Creating docker_app_1 ... done
Attaching to docker_app_1
app_1 |
app_1 | > app#1.0.0 dev:debug /usr/src/app
app_1 | > nodemon --config nodemon.json --env=development
app_1 |
app_1 | [nodemon] 2.0.2
app_1 | [nodemon] to restart at any time, enter `rs`
app_1 | [nodemon] watching dir(s): src/**/*
app_1 | [nodemon] watching extensions: ts
app_1 | [nodemon] starting `cross-env NODE_OPTIONS='--inspect=0.0.0.0:5858' ts-node -r tsconfig-paths/register ./src --env=development`
app_1 | Debugger listening on ws://0.0.0.0:5858/k3h42h4-h49d-4f00-adj877-60f6731548787
app_1 | For help, see: https://nodejs.org/en/docs/inspector
app_1 | Service started at ports:3000
Folder structure
App
|-- docker
| |-- docker-compose.yml
| |-- Dockerfile
| `-- .dockerignore
|-- nodemon.json
|-- package.json
|-- tsconfig.json
|-- tslint.json
`-- src
`-- index.ts
index.ts
import express, { Request, Response } from "express";
const app = express();
const port = process.env.PORT || 3000; // default port to listen
// define a route handler for the default home page
app.get("/", (req: Request, res: Response) => {
res.send("Hello worlds!");
});
// start the Express server
app.listen(port, () => {
console.log(`Service started at ports:${port}`);
});
docker-compose.yml
# docker-compose.yml
version: "3"
services:
app:
image: app:dev
build:
context: ../
dockerfile: ./docker/Dockerfile
ports:
- 3000:3000
volumes:
- ../src:/usr/src/app/src/
Dockerfile
FROM node:12-slim
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . ./
CMD [ "npm", "run", "dev:debug" ]
package.json
{
"name": "app",
"version": "1.0.0",
"description": "API to receive data",
"author": "Nikhil Gupta",
"main": "./dist/index.js",
"scripts": {
"dev:debug": "nodemon --config nodemon.json --env=development",
"dev:docker:debug": "docker-compose -f ./docker/docker-compose.yml up --build"
},
"dependencies": {
"cross-env": "^6.0.3",
"express": "^4.17.1",
"ts-node": "^8.5.4",
"tsconfig-paths": "^3.9.0",
"tslib": "^1.10.0"
},
"devDependencies": {
"#types/express": "^4.17.2",
"#types/node": "^12.12.21",
"nodemon": "^2.0.2",
"tslint": "^5.20.1",
"typescript": "^3.7.4"
}
}
nodemon.json
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/public"],
"inspect": true,
"exec": "cross-env NODE_OPTIONS='--inspect=0.0.0.0:5858' ts-node -r tsconfig-paths/register ./src"
}
Since the debugger is listening on port 5858 inside the container, you need to bind it to a port on the host machine if you want to connect to it from outside the container similar to how you have done for port 3000 in your compose file.
# docker-compose.yml
version: "3"
services:
app:
image: app:dev
build:
context: ../
dockerfile: ./docker/Dockerfile
ports:
- 3000:3000
- 5858:5858
volumes:
- ../src:/usr/src/app/src/
As mentioned in the comments by #ykit9 I did following
1) Added port 5858 into my docker-compose.yml
# docker-compose.yml
version: "3"
services:
app:
image: app:dev
build:
context: ../
dockerfile: ./docker/Dockerfile
ports:
- 3000:3000
- 5858:5858
volumes:
- ../src:/usr/src/app/src/
2) Added following configuration in VS Code's launch.json file.
{
"type": "node",
"request": "attach",
"name": "Attach to Docker",
"protocol": "auto",
"port": 5858,
"restart": true,
"localRoot": "${workspaceFolder}/src",
"remoteRoot": "/usr/src/app/src"
}

I can curl another docker container inside docker compose but not fetch in code

I can't fetch from server container to frontend container even though I am able to get curl response from inside frontend container.
I have a docker-compose set up with a frontend and server container.
I want to fetch server response from frontend, but i get the error GET http://server:5000/api/panels net::ERR_NAME_NOT_RESOLVED. I get the correct response if i execute the following command from inside the frontend container curl http://server:5000/api/panels
Dockerfile server
FROM node:11
ADD . /code
WORKDIR /code
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5000
CMD [ "node", "server" ]
Dockerfile frontend
FROM node:11
ADD . /frontend
WORKDIR /frontend
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm","start"]
docker-compose.yml
version: '3'
services:
server:
build: .
frontend:
depends_on:
- server
build: ./frontend
ports:
- "3030:3000"
api-call
this.callApi()
.then((res: ISolarPanels) => {
this.setState({ solarPanels: res })
})
.catch((err) => console.warn('server is offline?', err))
private callApi = async () => {
const response = await fetch(process.env.REACT_APP_URL+'/api/panels')
const body = await response.json()\
if (response.status !== 200) {
throw Error(body.message)
}
return body
}
package.json (i use dev script for local development and start for docker
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"#types/d3": "^5.0.1",
"d3": "^5.7.0",
"prettier": "^1.13.5",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-scripts-ts": "2.16.0",
"tslint-eslint-rules": "^5.3.1"
},
"scripts": {
"lint": "node_modules/.bin/tslint -c tslint.json 'src/**/{*.ts,*.tsx}'",
"dev": "REACT_APP_URL=http://localhost:3000 react-scripts-ts start",
"start": "REACT_APP_URL=http://server:5000 react-scripts-ts start",
"build": "react-scripts-ts build",
"test": "react-scripts-ts test --env=jsdom",
"eject": "react-scripts-ts eject"
},
"proxy": "http://localhost:5000/",
"devDependencies": {
"#types/node": "^10.3.3",
"#types/react": "^16.3.17",
"#types/react-dom": "^16.0.6",
"typescript": "^2.9.2"
}
}
For a quick fix, you can allow CORS on your server. here
And in your web application you can use:
0.0.0.0:5000/api for pointing to server.
Also, you would need to bind your port in server service in docker-compose.yml file.
server:
build: .
ports:
- "5000:5000"
To sum up what went wrong and how it was fixed.
The request was of-course sendt from the browser, and not the frontend container, therefore the server port needed to be exposed and CORS enabled from the serverside.

Resources