elewin / pi-weather-station

MIT License
295 stars 60 forks source link

Errors in Docker version #47

Open eiddor opened 1 year ago

eiddor commented 1 year ago

Hi there,

Thanks for an excellent project!

Issues are disabled on @SeanRiggs' repo, so I'm posting this here. I'm trying to run the Docker version of the repo on a Raspberry Pi 4, but I get this error:

pi@flight:~/docker $ docker compose up
Attaching to weather-station
weather-station  |
weather-station  | > pi-weather-station@2.0.0 start /app
weather-station  | > node ./server/index.js
weather-station  |
weather-station  | /app/node_modules/axios/index.js:1
weather-station  | import axios from './lib/axios.js';
weather-station  | ^^^^^^
weather-station  |
weather-station  | SyntaxError: Cannot use import statement outside a module
weather-station  |     at Module._compile (internal/modules/cjs/loader.js:892:18)
weather-station  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
weather-station  |     at Module.load (internal/modules/cjs/loader.js:812:32)
weather-station  |     at Function.Module._load (internal/modules/cjs/loader.js:724:14)
weather-station  |     at Module.require (internal/modules/cjs/loader.js:849:19)
weather-station  |     at require (internal/modules/cjs/helpers.js:74:18)
weather-station  |     at Object.<anonymous> (/app/server/geolocationCtrl.js:1:15)
weather-station  |     at Module._compile (internal/modules/cjs/loader.js:956:30)
weather-station  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
weather-station  |     at Module.load (internal/modules/cjs/loader.js:812:32)
weather-station  | npm ERR! code ELIFECYCLE
weather-station  | npm ERR! errno 1
weather-station  | npm ERR! pi-weather-station@2.0.0 start: `node ./server/index.js`
weather-station  | npm ERR! Exit status 1
weather-station  | npm ERR!
weather-station  | npm ERR! Failed at the pi-weather-station@2.0.0 start script.
weather-station  | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
weather-station  |
weather-station  | npm ERR! A complete log of this run can be found in:
weather-station  | npm ERR!     /root/.npm/_logs/2023-11-03T12_05_25_325Z-debug.log
weather-station exited with code 0

My Docker Compose file is:

version: '3'
services:
  weather-station:
    image: seanriggs/pi-weather-station:arm64 #or arm64 (i.e. RaspberryPi)
    container_name: weather-station
    ports:
      - "8080:8080"
    volumes:
      - appdata:/app
    restart: unless-stopped
volumes:
  appdata:

I can run pi-weather-station natively on the Pi and it works fine.

eiddor commented 1 year ago

FWIW - I decided to try to build my own Docker image for the project until Sean gets a chance to update his image (if he decides to do so.)

It seems to work fine as long as the /server/index.js workaround described on the repo is done. It's fairly basic and I'm sure doesn't follow any Docker best practices, but it works.

FROM node:18-alpine
RUN mkdir /home/node/app
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY --chown=node:node pi-weather-station/package*.json ./
USER node
RUN npm install
COPY --chown=node:node pi-weather-station/. .
EXPOSE 8080
CMD [ "npm", "start" ]

1) Put the above commands in a file names Dockerfile in a build directory. 2) git clone https://github.com/elewin/pi-weather-station.git in that directory 3) Apply the server/index.js workaround mentioned above. 3) Run: docker build -t weather-station:0.0.1 . in the build directory. 4) Run the container using your preferred method:

CLI

docker run -itd --name weather-station -p 8080:8080 -v -v appdata:/app weather-station:0.0.1

Docker Compose (my preferred method)

version: '3'
services:
  weather-station:
    image: weather-station:0.0.1
    container_name: weather-station
    ports:
      - "8080:8080"
    volumes:
      - appdata:/app
    restart: unless-stopped
volumes:
  appdata:

Feel free to ping me if you have any questions (or spot any issues).

SeanRiggs commented 1 year ago

Hey there,Thank you for sending this. I am in the military and deployed right now but will be back next week. I will look at all of what you have posted when I return. I don’t have a stable connection to test where I am at though. Thank you,Sean @. from my iPhoneOn Nov 4, 2023, at 9:09 AM, Roddie Hasan @.> wrote: FWIW - I decided to try to build my own Docker image for the project until Sean gets a chance to update his image (if he decides to do so.) It seems to work fine as long as the /server/index.js workaround described on the repo is done. It's fairly basic and I'm sure doesn't follow any Docker best practices, but it works. FROM node:18-alpine RUN mkdir /home/node/app RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app WORKDIR /home/node/app COPY --chown=node:node pi-weather-station/package*.json ./ USER node RUN npm install COPY --chown=node:node pi-weather-station/. . EXPOSE 8080 CMD [ "npm", "start" ]

Put the above commands in a file names Dockerfile in a build directory. git clone https://github.com/elewin/pi-weather-station.git in that directory Apply the server/index.js workaround mentioned above. Run: docker build -t weather-station:0.0.1 . in the build directory. Run the container using your preferred method:

CLI docker run -itd --name weather-station -p 8080:8080 -v -v appdata:/app weather-station:0.0.1 Docker Compose (my preferred method) version: '3' services: weather-station: image: weather-station:0.0.1 container_name: weather-station ports:

Feel free to ping me if you have any questions (or spot any issues).

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>