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"]
Related
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.
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
I can build and run a container with
docker build -t hopperweb:v5-full -f Dockerfile . &&
docker run -p 127.0.0.1:3000:8080 --rm -ti hopperweb:v5-full
However when I run the container I get this error: standard_init_linux.go:211: exec user process caused "exec format error"
docker run -p 127.0.0.1:3000:8080 --rm -ti hopperweb:v5-full
Why is it working when it's run after &&??
I can run the image with bash: docker run -p 127.0.0.1:3000:8080 --rm -ti hopperweb:v5-full bash without issue.
This is my DockerFile
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install --yes curl
RUN apt-get install --yes sudo ## maybe not necessary, but helpful
RUN apt-get install --yes gnupg
RUN apt-get install --yes git ## not necessary, but helpful
RUN apt-get install --yes vim ## not necessary, but helpful
## INSTALL NPM
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo 'deb https://dl.yarnpkg.com/debian/ stable main' | sudo tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update
RUN apt-get install --yes yarn
RUN apt-get install --yes npm
## COPY IN APP FILES
RUN mkdir /app
COPY hopperweb/ /app/hopperweb/
RUN chmod +x /app/hopperweb/start.sh
RUN /app/hopperweb/start.sh
The contents of start.sh:
#!/bin/bash
cd /app/hopperweb/
yarn start
In your first command, the docker run is never executed, as the last command (start.sh) is run during your build and it will never terminate. So you were still running docker build.
Change the following line
RUN /app/hopperweb/start.sh
to
CMD /app/hopperweb/start.sh
Do not confuse RUN with CMD. RUN actually runs a command and commits the result; CMD does not execute anything at build time, but specifies the intended command for the image.
See: https://docs.docker.com/engine/reference/builder/#cmd
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
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