Not able to run the UI while running through Docker - node.js

I am not able to fetch the UI while configuring the application using Docker. I am explaining my file below.
Dockerfile::
FROM node:10-alpine as node-builder
LABEL stage=builder
COPY ./app /app
# angular build
WORKDIR /app/mean-stack/angular-js
RUN npm cache clean --force
RUN npm install --no-package-lock
RUN npm install
RUN npm run build --configuration=production
FROM dockerhub.xxx.com/as-release-docker/ubot/mongo-db:4.0.3 as mongo
LABEL stage=mongo
FROM ubuntu:20.04
LABEL maintainer="ubot-tech-team#cisco.com"
LABEL build_date="2022-08-04"
RUN apt-get update
# SET TZ
RUN apt-get install -y tzdata
RUN echo 'Asia/Kolkata' > /etc/timezone
RUN dpkg-reconfigure --frontend noninteractive tzdata
# System tools
RUN apt-get install -y --no-install-recommends nginx
RUN apt-get install -y libcurl4 curl wget openssh-client supervisor telnet
# NodeJS
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs
# MongoDB
COPY --from=mongo /usr/bin/mongod /usr/bin/
RUN mkdir -p /data/db
# Setup nginx
RUN useradd --no-create-home nginx
RUN rm /etc/nginx/sites-enabled/default
RUN mkdir -p /var/log/supervisor
COPY server-conf/nginx.conf /etc/nginx/
COPY server-conf/ubot-nginx.conf /etc/nginx/conf.d/
RUN echo "uwsgi_read_timeout 7200s;" > /etc/nginx/conf.d/custom_timeout.conf
COPY server-conf/uwsgi.ini /etc/uwsgi/
COPY server-conf/supervisord.conf /etc/supervisor/
# ### EXPOSE PORTS
# ngnix web
EXPOSE 90
# MongoDB
EXPOSE 27017
# node-js
EXPOSE 8081
# Cleanup
RUN apt-get remove -y wget curl
RUN apt-get clean
# TLS self-signed certs
RUN mkdir -p /etc/nginx/ssl
CMD [ "node" ]
LABEL maintainer="ubot-tech-team#cisco.com"
# ### ubot app
COPY ./app /app
RUN mkdir -p /app/static/angular/generated
COPY --from=node-builder /app/mean-stack/angular-js/dist/ubot/ /app/static/angular/
# node build
WORKDIR /app/mean-stack/node-js
RUN npm cache clean --force
RUN npm install --no-package-lock
RUN npm install
# Copy start.sh script and set +x
COPY start.sh /start.sh
RUN chmod +x /start.sh
CMD ["/start.sh"]
Here I am creating container of NODE-ANGULAR which uses nginx but its not fetching the UI and throwing the below logs.
2022-09-02 05:18:55,360 INFO success: mongod entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2022-09-02 05:18:55,360 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2022-09-02 05:18:55,360 INFO success: node entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2022-09-02 05:18:55,361 INFO spawnerr: can't find command '/usr/local/bin/uwsgi'
2022-09-02 05:18:57,371 INFO spawnerr: can't find command '/usr/local/bin/uwsgi'
2022-09-02 05:19:00,377 INFO spawnerr: can't find command '/usr/local/bin/uwsgi'
2022-09-02 05:19:00,377 INFO gave up: uwsgi entered FATAL state, too many start retries too quickly
Here the image is created successfully but I am not able to run the application using this container. If any expert can give the solution will be very helpfull.

Related

Web app not accessible while using yarn in docker

I am trying to run a web app inside docker via yarn. Here's the docker file
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get upgrade -y
ENV TZ=Pacific/Auckland
RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
RUN apt-get install curl -y
RUN apt-get install npm -y
RUN apt-get install git -y
RUN npm cache clean -f
RUN npm install -g n
RUN n stable
RUN apt remove cmdtest -y
RUN apt remove yarn -y
RUN npm install -g yarn -y
RUN git config --global url."https://".insteadOf git://
EXPOSE 8080
COPY . .
RUN yarn
CMD yarn start
When I run yarn start as a non-docker the web app is accessible via localhost:8080
However when I start the docker instance via docker run -p 8080:8080 -itd webapp:latest & launch web browser & type in http://localhost:8080 the webapp isn't accessible.
Running docker logs against the container doesn't show any errors.
When I run curl, here is the error I see
curl "http://localhost:8080"
curl: (56) Recv failure: Connection reset by peer
I've no clue what is going on. Please could I request help to fix this problem.
the IP had to be bound on multiple interfaces for this to start working

How to run privileged Docker container for using systemctl

I am new to Docker and I am trying to use systemctl to restart a service. It constantly fails and Failed to get D-Bus connection: Operation not permitted. I understand that in order to bypass this I need to run a privileged docker container, however, this still does not produce my desired results.
Please see below for the steps I took and the files involved:
Docker command result
docker run --privileged testapp /sbin/init
Dockerfile
FROM openjdk:14.0.1
# Copies required files to the Linux container
COPY ./out/production/TestingApp/ /App
COPY test.sh /App
COPY expressvpn-2.5.1.1-1.x86_64.rpm /App
WORKDIR /App
RUN yum -y update
RUN yum -y install sudo && yum -y install expect && yum -y install systemd
RUN yum -y install expressvpn-2.5.1.1-1.x86_64.rpm
ENTRYPOINT ["java", "Main"]
test.sh
In my Main.java this shell script file is executed and the output is printed out to the console.
sudo systemctl start expressvpn.service
expressvpn status
try
docker run -u 0 testapp /sbin/init

Deploying node.js web app along with docker

WE have a node.js web app.We have deployed it on server with docker.
Its working fine with node version 0.10.25. But right now i have decided it to run on latest version of node 6.5.0
To accomplish this i modified the docker file which is now looking like below
FROM ubuntu:14.04
RUN echo 'deb http://security.ubuntu.com/ubuntu trusty-security main' | sudo tee -a /etc/apt/sources.list
RUN sudo apt-get update
RUN sudo apt-get install linux-libc-dev curl git-core krb5-multidev libkrb5-dev -y
RUN sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
RUN sudo apt-get install nodejs -y
RUN sudo ln -sf /usr/bin/nodejs /usr/bin/node
RUN ["/bin/bash", "-c", "node -v"]
RUN sudo npm cache clean
RUN sudo npm install -g bower -y
RUN sudo npm install -g gulp -y
#RUN sudo npm install -g node-sass
#RUN sudo npm install -g eslint -y
#RUN sudo npm install -g htmllint -y
RUN cd /root; git clone -b masterclone https://consultancy:Admin23#github.com/newapp/web.git
RUN cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod
EXPOSE 8000
CMD cd /root/web; NODE_ENV=production node server.js
Everything went fine except the below line which i guess causing the problem
"The command '/bin/sh -c cd /root/web; sudo npm install; sudo bower install --allow-root; gulp clean-build-app-prod' returned a non-zero code: 1"
Use the official node image. Here a example file.
FROM node:6.5
# Enviroment variables
ENV NPM_CONFIG_LOGLEVEL warn
ENV USER node
ENV HOMEDIR /data
# add user node and change dir working dir
RUN useradd -ms /bin/bash ${USER}
RUN mkdir -p ${HOMEDIR}
WORKDIR ${HOMEDIR}
# install all dependencies
COPY package.json ./
RUN npm install --production
# add node content
COPY . .
USER node
EXPOSE 8000
CMD ["npm", "start"]
It's probably simpler to base your file off of the official NodeJS image. For v6.5, that means that FROM ubuntu:14.04 becomes FROM node:6.5.
Also, instead of doing RUN cd /root/web over and over, you might want to change the working directory with WORKDIR /root/web.

NodeJS + Forever + Docker configuration doesn't work

I have a following Dockerfile:
FROM debian:stable
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_4.x | bash -
RUN apt-get install -y nodejs
RUN npm install forever -g
# App
ADD . /api
# Install app dependencies
RUN cd /api; npm install
EXPOSE 8080
CMD ["forever", "start", "/api/index.js", "8080"]
When I try to run docker run -p 8080:8080 my-app#1.0.0 I get the following message:
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: /api/index.js
and docker container stops.
What do I need to do to container work?
Docker exits as soon as the given command is finished. forever start SCRIPT is starting the script as a daemon in the background, and then exiting. That's why your container stops.
To make it work, you should start forever in the foreground by using forever SCRIPT. The CMD in your Dockerfile should be:
CMD ["forever", "/api/index.js", "8080"]

docker command attach running slow

i have docker container that adds 3 volumes and links to one other docker container. this linked container links to another one.
the container contains a nodejs server that is listening on one port.
the time for starting up the container is very short.
if i try to attach to that container it tooks sometimes 3 minutes until the attach-command runs.
could anyone give me a reason why the attach command tooks so long to start?
This is my Dockerfile:
FROM ubuntu:trusty
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get -y install curl
RUN apt-get -y install nodejs
RUN apt-get -y install npm
RUN npm install forever -g
RUN npm install n -g
RUN n 0.11.11
RUN npm install gulp -g
RUN mkdir -p data/dmcms-static-ng
RUN mkdir -p data/site-ng
RUN mkdir -p data/static-ng
ADD app-run.sh /app-run.sh
RUN chmod 755 /*.sh

Resources