Im trying to do a Dockerized Angular + Json-Server application but im having trouble setting json-server up, although I install it in the Dockerfile, using docker logs tells me that couldnt find the command json-server:
This is how my Dockerfile looks like:
FROM node:18 as CervantesJuradoBuild
ARG workdir="/home/CervantesJurado"
WORKDIR /appContainer
COPY /home/CervantesJurado/angular/A_Animals /appContainer
RUN echo pwd
WORKDIR /appContainer/A_Animals
RUN npm install -g @angular/cli
RUN npm cache clean --force
RUN npm install --legacy-peer-deps
RUN npm run build
FROM nginx as CervantesJuradoApp
ENV name="CervantesJurado"
LABEL author="$name"
RUN apt-get update &&
apt-get install -y openssh-server nodejs npm
RUN npm install -g json-server
RUN mkdir -p /run/sshd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN useradd -m -s /bin/bash $name &&
mkdir -p /home/$name/.ssh &&
chmod 700 /home/$name/.ssh
COPY /home/CervantesJurado/angular/A_Animals/id_rsa.pub /home/$name/.ssh/authorized_keys
COPY /home/CervantesJurado/angular/animals.json /home/$name/
RUN chown -R $name:$name /home/$name/.ssh &&
chmod 600 /home/$name/.ssh/authorized_keys
USER root
EXPOSE 22 80 3000
CMD ["sh", "-c", "json-server --watch /home/$name/animals.json --host 0.0.0.0 & service ssh start && nginx -g 'daemon off;'"]
COPY --from=CervantesJuradoBuild /appContainer/dist/a-animals /usr/share/nginx/html
And this is how i run it:
docker run -d -p 8080:80 -p 2222:22 -p 3000:3000 --name cervantes_container cervantesjurado:prueba3
After running the docker run command i use docker logs to see what happened:
docker logs cervantes_container
sh: 1: json-server: not found
2
Answers
If anyone came here as last resource and you are desperate, instead of using json-server use npm install [email protected] :)
Use RUN npm i -g [email protected].4 instead of RUN npm install -g json-server in docker file