Docker ENTRYPOINT not run two commands - docker

I have a docker-compose.yml with two services, Grafana and Ubuntu. I'm trying to run Prometheus and node_exporter commands in Ubuntu container through entrypoint but only works for the first command.
Dockerfile:
FROM ubuntu:20.04
ENV PROMETHEUS_VERISION=2.38.0
ENV NODE_EXPORTER_VERISION=1.4.0
RUN apt update -y && apt upgrade -y
RUN apt install -y wget
WORKDIR /
# Install Prometheus
RUN wget https://github.com/prometheus/prometheus/releases/downloa/v$PROMETHEUS_VERISION/prometheus-$PROMETHEUS_VERISION.linux-amd64.tar.gz && \
tar xvfz prometheus-$PROMETHEUS_VERISION.linux-amd64.tar.gz
ADD cstm_prometheus.yml /prometheus-$PROMETHEUS_VERISION.linux-amd64/cstm_prometheus.yml
EXPOSE 9090
# Install Node Exporter
RUN wget https://github.com/prometheus/node_exporter/releases/download/v$NODE_EXPORTER_VERISION/node_exporter-$NODE_EXPORTER_VERISION.linux-amd64.tar.gz && \
tar xvfz node_exporter-$NODE_EXPORTER_VERISION.linux-amd64.tar.gz
EXPOSE 9100
COPY ./cstm_entrypoint.sh /
RUN ["chmod", "+x", "/cstm_entrypoint.sh"]
ENTRYPOINT ["/cstm_entrypoint.sh"]
cstm_entrypoint.sh:
#!/bin/bash
./prometheus-$PROMETHEUS_VERISION.linux-amd64/prometheus --config.file=/prometheus-$PROMETHEUS_VERISION.linux-amd64/cstm_prometheus.yml
./node_exporter-$NODE_EXPORTER_VERISION.linux-amd64/node_exporter
When check the services on web browser i have access to:
grafana: 0.0.0.0:3000
prometheus: 0.0.0.0:9090
but not for node_exporter on 0.0.0.0:9100
Anybody could help me please?
Thanks in advance.

Your script waits for Prometheus to finish before it starts node_exporter. Try adding a & at the end of the Prometheus command to have it detach from the shell. Then the script will continue and run the node_exporter command. Like this
#!/bin/bash
./prometheus-$PROMETHEUS_VERISION.linux-amd64/prometheus --config.file=/prometheus-$PROMETHEUS_VERISION.linux-amd64/cstm_prometheus.yml &
./node_exporter-$NODE_EXPORTER_VERISION.linux-amd64/node_exporter

Related

Module /opt/rejson.so failed to load

ive been creating new intances for redis and clustering them. i would like my intsances to use rejson so im using redislabs/rejson. the only problem is when composing up i get this issue for all redis nodes.
here is the dockerfile for allredis nodes:
FROM redislabs/rejson:latest AS redis
ARG REDIS_PORT
WORKDIR /redis-workdir
# Installing OS level dependencies
RUN apt-get update
RUN apt-get install -y wget
RUN apt-get install -y gettext-base
RUN mkdir -p "/opt"
# Downloading redis default config
RUN wget https://raw.githubusercontent.com/wayofthepie/docker-rejson/master/redis.conf
RUN mv redis.conf redis.default.conf
COPY . .
ENV REDIS_PORT $REDIS_PORT
RUN envsubst < redis.conf > updated_redis.conf
RUN mv updated_redis.conf redis.conf
CMD redis-server ./redis.conf
its running the last line of this link https://raw.githubusercontent.com/wayofthepie/docker-rejson/master/redis.conf
thanks for helping out

Docker exits container

I am trying to build my own docker image for apache2 and PHP. Can anyone tell my why my container exits after run when it supposes to run ["apache2ctl", "-D", "FOREGROUND"]?
FROM ubuntu:latest
RUN apt update -y && apt upgrade -y
RUN apt install software-properties-common -y
RUN add-apt-repository ppa:ondrej/php -y
RUN apt update -y && apt upgrade -y
ARG DEBIAN_FRONTEND=noninteractive
RUN DEBIAN_FRONTEND=noninteractive apt install -y nano vim iputils-ping sudo git curl php php-cli php-fpm
RUN apt install -y php-json php-mysql
RUN apt install -y php-zip php-mbstring php-curl php-xml php-pear php-bcmath
RUN apt install psmisc -y
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOF_DIR /var/log/apache2
# RUN useradd -ms /bin/bash devwl
EXPOSE 80/tcp
ENTRYPOINT ["/bin/sh", "-c"]
CMD ["apache2ctl", "-D", "FOREGROUND"]
Build command:
docker build -t www .
Run command:
docker run -itd -p 80:80 www
Ouput docker ps:
Just tried to build your Dockerfile. docker logs shows a problem with start command. Running container without -D option works well...
CMD ["apache2ctl", "start"]
Do you need to use <IfDefine ...> in conf files?
You need to delete the ENTRYPOINT line.
Since you have both an ENTRYPOINT and a CMD, they get combined together into a single argument list. That means you have an effective command like
ENTRYPOINT+CMD ["/bin/sh", "-c", "apache2ctl", "-D", "FOREGROUND"]
But sh -c only reads in the single next argument and executes it. The remaining arguments would be accessible inside that string as positional parameters $0, $1, ... but unless you refer to one of those then the command you're eventually running is only apachectl with no arguments.
You only need to invoke a shell at all if your command uses shell features (referencing environment variables or running multiple commands). Yours doesn't, so you don't need anything that mentions a shell; just delete the ENTRYPOINT and have the existing CMD start Apache.
In a Dockerfile, you shouldn't usually need to say sh -c at all. If you do need to invoke a shell to run some command, you can use Docker shell syntax as a plain string without the JSON-array syntax; for example
# needs a shell because of $VARIABLE and command; command syntax
CMD touch "$APACHE_LOG_DIR/started"; exec apache2ctl -DFOREGROUND
(If you do need to override this command with docker run arguments or in a Compose command:, these syntaxes will not automatically insert a shell wrapper and there you do need to specifically say sh -c 'some command' if you need a shell to process the command string; again note the single quotes to make the command string a single argument.)

Docker port forwarding cannot see the output on browser

I am a newbie to Docker. I'm using ubuntu 14.04 as my OS and I've installed Docker Community Edition by following instructions from https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#set-up-the-repository
I have a created a docker file for my project and run it using docker-compose file.
My Dockerfile is as follows.
# ImageName
FROM node:8.8.1
# Create app required directories
ENV appDir /usr/src/app
RUN mkdir -p /usr/src/app /usr/src/app/datas /usr/log/supervisor
# Change working directory
WORKDIR ${appDir}
# Install dependencies
RUN apt-get update && \
apt-get -y install vim\
supervisor \
python3 \
python3-pip \
python3-setuptools \
groff \
less \
&& pip3 install --upgrade pip \
&& apt-get clean
RUN pip3 --no-cache-dir install --upgrade awscli
# Install app dependencies
COPY graphql/package.json /usr/src/app
RUN npm install
RUN npm install -g webpack
# Copy app source code
COPY graphql/ /usr/src/app
COPY datas/ /usr/src/app/datas
# Set Environment Variables
RUN echo export DATA_DIR=/usr/src/app/datas/ >> ~/.data_variables && \
echo "source ~/.data_variables" >> ~/.bash_login && \
echo "source ~/.data_variables" >> ~/.bashrc
COPY supervisord.conf /etc/supercvisor/conf.d/supervisord.conf
# Expose API port to the outside
EXPOSE 5000
# Launch application
CMD ["/usr/bin/supervisord", "-c", "/etc/supercvisor/conf.d/supervisord.conf"]
My docker-compose file
version: '3'
services:
web:
build: .
image: graphql_img
container_name: graphql_img_master
ports:
- "5000:5000"
My supervisord.conf file
[supervisord]
nodaemon=true
[program:babelWatch]
command=npm run babelWatch
[program:monitor]
command=npm run monitor
As you can see I've exposed the port 5000, but when I try to check the output on the browser using the command localhost:5000/graphql it shows an error
This site can’t be reached
I even tried to check for the ip address of docker container using "docker inspect" command and I've used that container ip address with the port still I'm getting the error. Can somebody please help me out on this. Any help would be much appreciated.
Additionally, it would also really helpful to know how to make the program "run monitor" to run on foreground using supervisor

Dockerfile with LAMP running (Ubuntu)

I'm trying to create a Docker (LAMP) image with the following
Dockerfile:
FROM ubuntu:latest
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
apache2 \
mysql-server \
php7.0 \
php7.0-bcmath \
php7.0-mcrypt
COPY start-script.sh /root/
RUN chmod +x /root/start-script.sh && /root/start-script.sh
start-script.sh:
#!/bin/bash
service mysql start
a2enmod rewrite
service apache2 start
I build it with:
docker build -t resting/ubuntu .
Then run it with:
docker run -it -p 8000:80 -p 5000:3306 -v $(pwd)/html:/var/www/html resting/ubuntu bash
The problem is, the MYSQL and Apache2 service are not started.
If I run /root/start-script.sh manually in the container, port 80 maps fine to port 8000, but I couldn't connect to MYSQL with 127.0.0.1:5000.
How can I ensure that the services are running when I spin up a container with the image, and map MYSQL out to my host machine?
You need to change the execution of the script to a CMD instruction.
FROM ubuntu:latest
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
apache2 \
mysql-server \
php7.0 \
php7.0-bcmath \
php7.0-mcrypt
COPY start-script.sh /root/
RUN chmod +x /root/start-script.sh
CMD /root/start-script.sh
Althought this works, this is not the right way to manage containers. You should have one container for your Apache2 and another one for MySQL.
Take a look to this article that build a LAMP stack using Docker-Compose: https://www.kinamo.be/en/support/faq/setting-up-a-development-environment-with-docker-compose
you need multiple images - one for each service or app.
A Docker container is not a virtual machine in which you run an entire stack. It is a virtual application, running one primary process.
If you need php, apache and mysql, then you will need 3 docker containers. one for your php app, one for apache and one for mysql.

Starting Multiple service in Dockefile

I have one dockerfile as below.
FROM centos:centos6
RUN yum install httpd* -y
RUN yum install mysql* -y
ENTRYPOINT service mysqld start && bash
ENTRYPOINT service httpd start && bash
Docker file running successful but when i enter into the container only one service is in start start that is httpd.
I want to start both the service automatically using dockerfile.
Please let us know how to do that
You should create a entrypoint.sh file:
#!/bin/bash
service mysqld start
service httpd start
And Dockerfile:
FROM centos:centos6
RUN yum install httpd* -y
RUN yum install mysql* -y
COPY ./entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
You also try to use supervisord in your docker image

Resources