CannerCMS / cannercms

⚡️ Content Management Framework creates custom CMS fast and easy. Support data sources such as Firebase/Firestore, GraphQL and Restful APIs.
https://www.cannerdata.com
Apache License 2.0
2.43k stars 145 forks source link

canner script:serve does not run server in Docker #111

Open Bedrock02 opened 5 years ago

Bedrock02 commented 5 years ago

I am trying to set a docker container for my canner project. Locally when I serve on my computer I see Starting CMS server on http://localhost:9090

However within the docker container I see everything except for that it is serving on 9090

docker-compose.yml

version: '3'
services:
  app:
    container_name: 'canner_container'
    build: .
    command: "canner script:serve"
    image: 'canner:latest'
    ports:
     - "9090:9090"

Dockerfile

FROM node:7

WORKDIR /app

COPY package.json /app

RUN npm install

RUN npm install --global @canner/cli

COPY . /app

EXPOSE 9090

docker-compose up --build

Building app
Step 1/7 : FROM node:7
 ---> d9aed20b68a4
Step 2/7 : WORKDIR /app
 ---> Using cache
 ---> 75bea9556994
Step 3/7 : COPY package.json /app
 ---> Using cache
 ---> 4d740e3df2a3
Step 4/7 : RUN npm install
 ---> Using cache
 ---> 9d20f08d548d
Step 5/7 : RUN npm install --global @canner/cli
 ---> Using cache
 ---> 2a5fcc62764a
Step 6/7 : COPY . /app
 ---> Using cache
 ---> a4e626559270
Step 7/7 : EXPOSE 9090
 ---> Using cache
 ---> bff49a6fb6ff
Successfully built bff49a6fb6ff
Successfully tagged canner:latest
canner_container is up-to-date
Attaching to canner_container
canner_container | ℹ 「wdm」: Hash: 76b937a67fca8c43997c
canner_container | Version: webpack 4.20.2
canner_container | Time: 5604ms
canner_container | Built at: 10/04/2018 4:14:45 PM
canner_container |                                Asset      Size  Chunks             Chunk Names
canner_container | d89f77c19e5d3aa366ba1498dddd64ef.svg  11.2 KiB          [emitted]
canner_container |                          0.bundle.js  11.3 KiB       0  [emitted]
canner_container |                          1.bundle.js  22.3 KiB       1  [emitted]
canner_container |                          2.bundle.js  1.41 MiB       2  [emitted]
canner_container |                          3.bundle.js   140 KiB       3  [emitted]
canner_container |                       main.bundle.js  12.1 MiB    main  [emitted]  main
canner_container |                           index.html  1.97 KiB          [emitted]
canner_container | Entrypoint main = main.bundle.js
canner_container | [../tmp/_cnr-17Z4R3KrdgRvX.js] /tmp/_cnr-17Z4R3KrdgRvX.js 806 bytes {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/lib/serve/app.js] /usr/local/lib/node_modules/@canner/cli/lib/serve/app.js 2.46 KiB {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/loglevel/lib/loglevel.js] /usr/local/lib/node_modules/@canner/cli/node_modules/loglevel/lib/loglevel.js 7.68 KiB {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/sockjs-client/dist/sockjs.js] /usr/local/lib/node_modules/@canner/cli/node_modules/sockjs-client/dist/sockjs.js 177 KiB {main} [built]
canner_container | [react-dom] external "ReactDOM" 42 bytes {main} [built]
canner_container | [0] multi (webpack)-dev-server/client?http://localhost /tmp/_cnr-17Z4R3KrdgRvX.js 40 bytes {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/strip-ansi/index.js] /usr/local/lib/node_modules/@canner/cli/node_modules/strip-ansi/index.js 161 bytes {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/url/url.js] /usr/local/lib/node_modules/@canner/cli/node_modules/url/url.js 22.8 KiB {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack-dev-server/client/index.js?http://localhost] (webpack)-dev-server/client?http://localhost 7.78 KiB {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.58 KiB {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.05 KiB {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack/hot sync ^\.\/log$] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {main} [built]
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 77 bytes {main} [built]
canner_container | [./canner.schema.js] 10.1 KiB {main} [built]
canner_container | [react] external "React" 42 bytes {main} [built]
canner_container |     + 1712 hidden modules
canner_container | Child html-webpack-plugin for "index.html":
canner_container |          Asset      Size  Chunks  Chunk Names
canner_container |     index.html  1.39 MiB       0
canner_container |     Entrypoint undefined = index.html
canner_container |     [../usr/local/lib/node_modules/@canner/cli/node_modules/html-webpack-plugin/lib/loader.js!../usr/local/lib/node_modules/@canner/cli/lib/serve/template.html] /usr/local/lib/node_modules/@canner/cli/node_modules/html-webpack-plugin/lib/loader.js!/usr/local/lib/node_modules/@canner/cli/lib/serve/template.html 2.14 KiB {0} [built]
canner_container |     [../usr/local/lib/node_modules/@canner/cli/node_modules/lodash/lodash.js] /usr/local/lib/node_modules/@canner/cli/node_modules/lodash/lodash.js 527 KiB {0} [built]
canner_container |     [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 509 bytes {0} [built]
canner_container |     [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 519 bytes {0} [built]
canner_container | ℹ 「wdm」: Compiled successfully.
canner_container | ℹ 「wdm」: Compiling...
canner_container | ℹ 「wdm」: Hash: 3661bc3f43a457e94e0f
canner_container | Version: webpack 4.20.2
canner_container | Time: 550ms
canner_container | Built at: 10/04/2018 4:14:46 PM
canner_container |                                Asset      Size  Chunks             Chunk Names
canner_container | fc7f5059da3077ae91c8.hot-update.json  44 bytes          [emitted]
canner_container | d89f77c19e5d3aa366ba1498dddd64ef.svg  11.2 KiB
canner_container |                          0.bundle.js  11.3 KiB       0
canner_container |                          1.bundle.js  22.3 KiB       1
canner_container |                          2.bundle.js  1.41 MiB       2
canner_container |                          3.bundle.js   140 KiB       3
canner_container |                       main.bundle.js  12.1 MiB    main  [emitted]  main
canner_container | 76b937a67fca8c43997c.hot-update.json  35 bytes          [emitted]
canner_container |                           index.html  1.97 KiB          [emitted]
canner_container | Entrypoint main = main.bundle.js
canner_container | [../tmp/_cnr-17Z4R3KrdgRvX.js] /tmp/_cnr-17Z4R3KrdgRvX.js 806 bytes {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/lib/serve/app.js] /usr/local/lib/node_modules/@canner/cli/lib/serve/app.js 2.46 KiB {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/loglevel/lib/loglevel.js] /usr/local/lib/node_modules/@canner/cli/node_modules/loglevel/lib/loglevel.js 7.68 KiB {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/sockjs-client/dist/sockjs.js] /usr/local/lib/node_modules/@canner/cli/node_modules/sockjs-client/dist/sockjs.js 177 KiB {main}
canner_container | [react-dom] external "ReactDOM" 42 bytes {main}
canner_container | [0] multi (webpack)-dev-server/client?http://localhost /tmp/_cnr-17Z4R3KrdgRvX.js 40 bytes {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/strip-ansi/index.js] /usr/local/lib/node_modules/@canner/cli/node_modules/strip-ansi/index.js 161 bytes {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/url/url.js] /usr/local/lib/node_modules/@canner/cli/node_modules/url/url.js 22.8 KiB {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack-dev-server/client/index.js?http://localhost] (webpack)-dev-server/client?http://localhost 7.78 KiB {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.58 KiB {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.05 KiB {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack/hot sync ^\.\/log$] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {main}
canner_container | [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 77 bytes {main}
canner_container | [./canner.schema.js] 10.1 KiB {main}
canner_container | [react] external "React" 42 bytes {main}
canner_container |     + 1712 hidden modules
canner_container | Child html-webpack-plugin for "index.html":
canner_container |                                    Asset      Size  Chunks             Chunk Names
canner_container |                               index.html  1.39 MiB       1
canner_container |     fc7f5059da3077ae91c8.hot-update.json  44 bytes          [emitted]
canner_container |     Entrypoint undefined = index.html
canner_container |     [../usr/local/lib/node_modules/@canner/cli/node_modules/html-webpack-plugin/lib/loader.js!../usr/local/lib/node_modules/@canner/cli/lib/serve/template.html] /usr/local/lib/node_modules/@canner/cli/node_modules/html-webpack-plugin/lib/loader.js!/usr/local/lib/node_modules/@canner/cli/lib/serve/template.html 2.14 KiB {1}
canner_container |     [../usr/local/lib/node_modules/@canner/cli/node_modules/lodash/lodash.js] /usr/local/lib/node_modules/@canner/cli/node_modules/lodash/lodash.js 527 KiB {1}
canner_container |     [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 509 bytes {1}
canner_container |     [../usr/local/lib/node_modules/@canner/cli/node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 519 bytes {1}
canner_container | ℹ 「wdm」: Compiled successfully.
chilijung commented 5 years ago

@Bedrock02 Hi, since canner:serve is using https://github.com/webpack/webpack-dev-server to create local server for local development. Since we are not really familiar with docker, so we didn't know why this is not working right.

If you are trying to hosting a web server that hosting Canner CMS you should consider using https://www.canner.io/docs/guides-community-intro.html our Canner component to host within your web server. Which will be the same as how you setup other web servers.

EarthlingDavey commented 5 years ago

@Bedrock02 , did you get it to work with docker?

EarthlingDavey commented 5 years ago

With some help from comments in the issue cli: No such file or directory #118 I have found a solution to your question.

You must install version 2.6.3 of @canner/cli . I found that it error'd if installed globally so it's set as a dependancy in package.json

The command canner script:serve /app/schema/canner.schema.js --host 0.0.0.0 --port 9090 is used to start the serve. Setting the host to 0.0.0.0 is important for docker to expose the port.

My files are below. Once you have these, docker-compose up works.

docker-compose.yml

version: '3'
services:
  app:
    build: .
    ports:
      - "9090:9090"
    volumes:
      - ./schema:/app/schema

Dockerfile

FROM node:6
WORKDIR /app
COPY ./package.json /app
EXPOSE 9090
COPY ./docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

docker-entrypoint.sh

#!/bin/sh
npm install
npm start

package.json

{
  "name": "docker-sample",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start": "canner script:serve /app/schema/canner.schema.js --host 0.0.0.0 --port 9090"
  },
  "dependencies": {
    "@canner/cli": "2.6.3"
  }
}

schema/canner.schema.js

/** @jsx builder */
import builder from "canner-script";

export default (
  <root>
    <object keyName="info">
      <string keyName="name" />
    </object>
  </root>
);