I have created a Dockerfile, when run with docker-compose displays 'Hello world' in the browser. Now I want to be able to display a simple react form with some fields to enter text in and a submit button. Is there examples of any simple projects out there that I can just use. How will I update my files, that I have shown below
These are the files that I cam using:
Package.json -
{
"name": "nodejs-hello",
"version": "1.0.0",
"description": "des",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "hh",
"license": "ISC",
"keywords": [
"h"
],
"dependencies": {
"express": "^4.17.1"
}
}
index.js -
//now it load express module with `require` directive
var express = require('express')
var app = express()
const PORT = 8080;
//Define request response in root URL (/) and response with text Hello World!
app.get('/', function (req, res) {
res.send('Hello World')
})
//Launch listening server on port 8080 and consoles the log.
app.listen(PORT, function () {
console.log('app listening on port ' + PORT)
})
Dockerfile -
FROM node:latest
WORKDIR /app
COPY package.json index.js ./
RUN npm install
EXPOSE 8080
CMD node index.js
Docker Compose -
version: "3"
services:
web:
image: my-image:1.0
build: .
ports:
- '8080:8080'
https://medium.com/faun/a-simple-docker-setup-for-simple-hello-world-nodejs-application-bcf79bb608a0
What I have now is similar to the example in that link.
Now I just want to be able to display a react form in the browser.
Just create your React app and then add this line to copy the src files into the container:
COPY . .
Also, change the CMD
(if you're using a CRA) to this:
CMD [ "npm", "start" ]
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.