I used the following command to run the container :
docker run -p 3333:3333 -d maill/node-web-app
Here is the result of docker ps :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f26270107bfa maill/node-web-app "npm run dev" 49 seconds ago Up 46 seconds 0.0.0.0:3000->3000/tcp musing_fermi
However when I try to access webserver on host using localhost:3333 it doesn't work.
I am using windows 10 pro.
docker logs musing_fermi shows:
DONE Compiled successfully in 3541ms16:04:50 | OPEN localhost:3000
Dockerfile :
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 3333
CMD [ "npm", "run", "dev" ]
package.json :
{
"name": "webapp-pst-horizon",
"version": "1.0.0",
"description": "Webapp pour les formations enedis",
"author": "Léo Coletta",
"private": true,
"scripts": {
"dev": "cross-env HOST=0.0.0.0 PORT=3333 nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"precommit": "npm run lint"
},
"dependencies": {
"#nuxtjs/axios": "^5.3.1",
"#nuxtjs/proxy": "^1.2.4",
"axios": "^0.18.0",
"babel-polyfill": "^6.26.0",
"cookie": "^0.3.1",
"js-cookie": "^2.2.0",
"nuxt": "^1.4.1",
"vuetify": "^1.0.19",
"webpack": "^3.1.0"
},
"devDependencies": {
"babel-eslint": "^8.2.3",
"cross-env": "^5.2.0",
"eslint": "^4.9.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-vue": "^4.5.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2"
}
}
Based on what you have in the question so far, and that you have OPEN localhost:3000 coming from your container logs, I'd guess your application is listening on localhost. This is != localhost outside the container. You need to configure your application to listen on 0.0.0.0 inside the container.
To go along with johnharris85's answer, add the following to your package.json:
From nuxt documentation on "How to edit HOST and PORT?"
You can configure the PORT with 3 different ways:
...
...
Via a nuxt config in the package.json:
Inside your package.json:
"config": {
"nuxt": {
"host": "0.0.0.0",
"port": "3333"
}
},
"scripts": {
"dev": "nuxt"
}
Related
I've been trying to start up a development environment for a Docker image that I've found on GitHub, but I've had a great deal of trouble with it. Whenever I run docker-compose up, I'm faced with the following error:
assets_1 | /bin/sh: 1: run-p: not found
assets_1 | error Command failed with exit code 127.
assets_1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I then install run-p with the command npm install run-p, but this leads me to the exact same error, and I have no idea how to solve this issue.
I'm unsure if this issue resides in this specific Docker image that I've downloaded from GitHub, but the owner seems to have gotten everything working fairly simply on his end.
Here's my package.json:
{
"name": "sql-language-server",
"displayName": "SQL Language Server",
"description": "SQL Language Server Extension for VSC",
"version": "0.12.0",
"main": "./packages/client/out/extension",
"repository": {
"type": "git",
"url": "git+https://github.com/joe-re/sql-language-server.git"
},
"keywords": [
"sql",
"language-server",
"language-server-protocol",
"lint",
"autocompletion"
],
"bugs": {
"url": "https://github.com/joe-re/sql-language-server"
},
"author": "joe-re <joe.tialtngo#gmail.com>",
"license": "MIT",
"publisher": "joe-re",
"scripts": {
"vsc-compile": "npm run vsc-compile:client && npm run vsc-compile:server",
"vsc-compile:client": "cd ./packages/client && yarn run compile",
"vsc-compile:server": "cd ./packages/server && yarn run prepare-vsc-extension",
"watch": "run-p watch:client watch:server",
"watch:client": "cd ./packages/client && yarn run watch",
"watch:sqlint": "cd ./packages/sqlint && yarn run watch",
"watch:server": "wait-on ./packages/sqlint/dist/src/index.js && cd ./packages/server && yarn run watch:index",
"watch:dev-server:client": "cd ./example/monaco_editor && yarn run webpack:watch",
"watch:dev-server:server": "wait-on ./packages/server/dist/src/index.js && cd ./example/monaco_editor && yarn run start",
"dev": "run-p watch:sqlint watch:server watch:dev-server:client watch:dev-server:server",
"vscode:prepublish": "yarn run vsc-compile"
},
"engines": {
"vscode": "^1.45.1"
},
"activationEvents": [
"onLanguage:sql"
],
"contributes": {
"commands": [
{
"command": "extension.switchDatabaseConnection",
"title": "Switch database connection",
"category": "SQLLanguageServer"
},
{
"command": "extension.fixAllFixableProblems",
"title": "Fix all auto-fixable problems",
"category": "SQLLanguageServer"
},
{
"command": "extension.rebuildSqlite3",
"title": "Rebuild SQLite3 Client",
"category": "SQLLanguageServer"
}
],
"configuration": {
"type": "object",
"title": "sql-language-server configuration",
"properties": {
"sqlLanguageServer.connections": {
"scope": "resource",
"type": "array",
"default": [],
"description": "connection setting"
},
"sqlLanguageServer.lint": {
"scope": "resource",
"type": "object",
"default": {},
"description": "lint setting"
}
}
}
},
"private": true,
"workspaces": [
"packages/*",
"example/*"
],
"devDependencies": {
"npm-run-all": "^4.1.3",
"wait-on": "^5.0.1"
},
"dependencies": {
"electron-rebuild": "^1.11.0",
"run-p": "0.0.0",
"sqlite3": "^4.2.0"
}
}
Here is docker-compose.yaml
version: '3'
services:
assets:
build:
context: .
dockerfile: dockerfile
volumes:
- .:/opt/sql-language-server:rw
command: 'yarn dev' # 'tail -f /dev/null'
ports:
- '3000:3000'
postgres:
image: postgres:10
restart: always
environment:
POSTGRES_DB: postgres_db
POSTGRES_USER: sqlls
POSTGRES_PASSWORD: sqlls
volumes:
- postgres:/var/lib/postgresql/data
mysql:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: mysql_db
MYSQL_USER: sqlls
MYSQL_PASSWORD: sqlls
volumes:
- mysql:/var/lib/mysql
volumes:
postgres:
mysql:
And here is the dockerfile:
FROM node:12
COPY ./package.json yarn.lock /opt/sql-language-server/
COPY ./packages/server/package.json /opt/sql-language-server/packages/server/
COPY ./packages/sql-parser/package.json /opt/sql-language-server/packages/sql-parser/
COPY ./packages/sqlint/package.json /opt/sql-language-server/packages/sqlint/
COPY ./example/monaco_editor/package.json /opt/sql-language-server/example/monaco_editor/
COPY ./example/monaco_editor/.sqllsrc.personal.json /root/.config/sql-language-server/.sqllsrc.json
WORKDIR /opt/sql-language-server
RUN yarn
I have a react app which starts outside of Docker but not inside.
I'm running a backend Node app which works in Docker, this failing front-end is the issue. From previous threads and questions i'm certain it is not the 'globby' module at fault, it's likely to be my config or installation.
The error:
react-scripts start
/usr/src/app/node_modules/react-dev-utils/node_modules/globby/index.js:49
...taskOptions
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/src/app/node_modules/react-dev-utils/globby.js:10:14)
npm info lifecycle react-frontend#0.1.0~start: Failed to exec start script
npm ERR! Linux 4.19.128-microsoft-standard
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.11.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! react-frontend#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
My Dockerfile
FROM node:6.11.1
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
My package.json
{
"name": "react-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"globby": "^11.0.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "^4.0.1",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
What i've tried:
deleting node_modules and redoing npm install
Docker rebuilds
After #vpalmerini pointed out the Node version, I updated to 14.15.4-alpine and ran
docker-compose build
docker-compose up
So now my Dockerfile contains
FROM node:14.15.4-alpine
The app is now running as expected.
I dockerirized a vue.js app init by webpack, and run it with docker-compose. It runs with no problem in terminal, but when I go to the browser: "impossibile to reach ip".
I use docker-toolbox (thus, a VM).
First of all I make a new folder and execute the follow lines in order to init a new vue project using webpack:
npm install -g vue-cli
vue init webpack vueapp2
Now, if I run my applicatoin using npm run dev it works fine. In order to dockerizing it, I make a Dockerfile:
FROM node:alpine
RUN npm install -g vue-cli
WORKDIR '/app'
COPY ./package*.json ./
RUN npm install
COPY ./ ./
CMD [ "npm", "run", "dev"]
and a docker-compose.yml:
version: "3"
services:
node-app:
build: .
ports:
- "8080:8000"
In order to works with Docker using docker Toolbox, I have to map local-machine port to container-port (8080:8000). That's should works fine because I do similar things with a vue.js app serve by live-server succesfully (https://github.com/Aragorn1992gb/vue-liveserver-dockerized). But that's that use webpack no: it says "impossible to reach ip" when I digit container ip: http://192.168.99.100:8080/.
The line CMD [ "npm", "run", "dev"] on Dockerfile should execute command "npm run [script 'dev' staying on package.json]". That's my package.json:
{
"name": "vue-app2",
"version": "1.0.0",
"description": "A Vue.js project",
"author": "Aragorn1992gb <giacomobrunetta#gmail.com>",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"lint": "eslint --ext .js,.vue src",
"build": "node build/build.js"
},
"dependencies": {
"vue": "^2.5.2",
"vue-router": "^3.0.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-eslint": "^8.2.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"eslint": "^4.15.0",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-vue": "^4.0.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
I found different solutions but without any success. One of the advise is it to add --host 0.0.0.0 to dev like this: "dev": "webpack-dev-server --host 0.0.0.0 --inline --progress --config build/webpack.dev.conf.js",, because it has to reach my docker ip, but stil not working. Actually must be a problem with that "dev" script, there is some problem to run it using dockerfile. This is my project on repo: https://github.com/Aragorn1992gb/vue-webapp-dockerizing
I just change contaner port from 8000 to 8080:
version: "3"
services:
node-app:
build: .
ports:
- "8080:8080"
Because on config/index.js the specified port is 8080. I can also change that port (i.e. 8000) and change it also in docker.compose.yml (i.e. 8080:8000).
Putting also --host 0.0.0.0 to dev, like that:
"dev": "webpack-dev-server --host 0.0.0.0 --inline --progress --config build/webpack.dev.conf.js",
Because webpack listen only on localhost container, I must allow requests from other interfaces (container ip)
I'm creating a rails application from scratch using the following blog which needs me to run rails s and then yarn start in the /client folder of the application (where all the JS and React components will live).
The /client/package.json file has some scripts configured to run a server that detects changes in my react components and reloads the components automatically:
client/package.json:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:3001"
}
I use a program called hivemind which is a Procfile manager and I would like both the rails server process and the yarn process to run together in the same terminal.
I'd like to do something like this in my Profile:
server: bin/rails server
react: yarn start
The problem is that Profile lives in the root of my application and I have to change directory into client and then run yarn start.
TL;DR:
Is there an option with yarn run that you can tell it to run from another folder or read a package.json file in another folder and have it run the script in that file?
You can write cmd arguments in Procfile
try changing react command to
react: cd client && yarn start
It will change the current directory and runs your script
When you run yarn [command] yarn looks for a file locally called package.json. You can add yarn commands inside the "scripts" section of this file. In my own rails app root directory I added a "start" command that did what Sumanth's answer does but now I can just have
react: yarn start
in my Procfile.
Below is the edited version of my package.json file in my app's root path:
{
"name": "create-repack-app",
"version": "1.0.0",
"scripts": {
"build": "cd client && npm install --only=dev && npm install && npm run build && cd ..",
"deploy": "cp -a client/build/. public/",
"heroku-postbuild": "npm run build && npm run deploy && echo 'Client Built'",
"start": "cd client && yarn start"
},
"keywords": [],
"author": "",
"license": "ISC"
}
I have an Ionic project already working and running. I wanted to dockerize it so I wrote and added Dockerfile and .dockerignore to it manually. My project structure looks like following:
My package.json:
{
"name": "example",
"version": "1.1.1",
"description": "example: An Ionic project",
"dependencies": {
"angular-messages": "^1.5.1",
"gulp": "^3.5.6",
"gulp-concat": "^2.2.0",
"gulp-minify-css": "^0.3.0",
"gulp-rename": "^1.2.0",
"gulp-sass": "^2.0.4"
},
"devDependencies": {
"bower": "^1.3.3",
"gulp-util": "^2.2.14",
"shelljs": "^0.3.0"
},
"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-splashscreen",
"cordova-plugin-statusbar",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [
"android"
]
}
My bower.json:
{
"name": "HelloIonic",
"private": "true",
"dependencies": {
"angular": "~1.3.1",
"angular-route": "~1.3.1",
"angular-cookies": "~1.4.0",
"bootstrap": "~3.3.0",
"bootstrap-material-design": "~0.1.5",
"jquery": "~2.1.1",
"ngDialog": "~0.3.3",
"underscore": "~1.7.0",
"ionic": "^1.2.4",
"angular-resource": "^1.5.2",
"angular-google-chart": "^0.1.0",
"angular-ui-router-styles": "^1.1.0",
"angular-audio": "^1.7.2"
},
"resolutions": {
"angular": "~1.3.1"
}
}
My Dockerfile:
FROM node:4.0
COPY . /www/app
RUN npm install -g ionic cordova
RUN npm install -g bower
RUN npm install -g gulp
WORKDIR /www/app
RUN npm install
RUN echo '{"allow_root":true}' > /root/.bowerrc
RUN bower install
EXPOSE 8100 35729
ENTRYPOINT ["ionic"]
CMD ["serve", "--all", "--port", "8100", "--livereload-port", "35729"]
And .dockerignore:
Dockerfile
config.xml
.sass-cache
.editorconfig
.io-config.json
.dockerignore
hooks/
platforms/
node_modules/
resources/
plugins/
www/css/*.css
*.zip
*.tar*
It is built successfully (I guess, as there are no errors) but when I execute docker build -t ionic-preview . but when I run it with docker run -p 8100:8100 -it ionic-preview - > it runs but no static files are loaded.
Is there anything wrong with my dockerfile? Or what is the issue?
UPDATE:
When normally I run my application, I see like following:
With docker I see this:
You did not share your data yet as in: -v /src/webapp:/webapp
So you could do:
docker run -p 8100:8100 -v /src/webapp:/webapp -it ionic-preview
Change the maps to your maps.
Source: https://docs.docker.com/engine/tutorials/dockervolumes/#locating-a-volume