Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in Docker version #47

Open
eiddor opened this issue Nov 3, 2023 · 2 comments
Open

Errors in Docker version #47

eiddor opened this issue Nov 3, 2023 · 2 comments

Comments

@eiddor
Copy link

eiddor commented Nov 3, 2023

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  | > [email protected] 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! [email protected] start: `node ./server/index.js`
weather-station  | npm ERR! Exit status 1
weather-station  | npm ERR!
weather-station  | npm ERR! Failed at the [email protected] 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
Copy link
Author

eiddor commented Nov 4, 2023

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.
  4. Run: docker build -t weather-station:0.0.1 . in the build directory.
  5. 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
Copy link
Contributor

SeanRiggs commented Nov 7, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants