'Docker compose failed in production server but not in pc
I have developed an application in node js that needs to connect to MongoDB because of that I implemented a wait-for.sh script, when I run the entire application in my computer docker everything goes well, but when I run it in my digital ocean ubuntu 20.04 server it crashed with the following error
Node.js v17.4.0
/usr/app/wait-for.sh:3
# original script: https://github.com/eficode/wait-for/blob/master/wait-for
^
SyntaxError: Invalid or unexpected token
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1026:15)
at Module._compile (node:internal/modules/cjs/loader:1061:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
This is the dockerfile
FROM node:17-alpine
WORKDIR /usr/app
COPY package.json .
RUN npm install --quiet
COPY . .
COPY wait-for.sh wait-for.sh
RUN chmod +x wait-for.sh
# Deleting windows characteres
RUN apt-get install -y dos2unix # Installs dos2unix Linux
RUN find . -type f -exec dos2unix {} \; # recursively removes windows related stuff
The docker compose
version: '3.3'
services:
monitor:
build:
context: .
dockerfile: Dockerfile
container_name: app
restart: unless-stopped
volumes:
- .:/usr/app/
- /usr/app/node_modules
networks:
- app-network
command: ./wait-for.sh db:27017 -- node index.js
db:
image: mongo
container_name: db
restart: unless-stopped
volumes:
- dbdata:/data/db
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
dbdata:
node_modules:
And the wait for link wait for script
I don't know why is this happening
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
