Permission denied in Minikube Docker Script - docker

I am new to Minikube and Docker. I have a setup of Minikube with three pods of apache spark.
One spark master and two spark worker. My docker file for spark master is as below,
# base image
FROM openjdk:11
# define spark and hadoop versions
ENV SPARK_VERSION=3.2.0
ENV HADOOP_VERSION=3.3.1
# download and install hadoop
RUN mkdir -p /opt && \
cd /opt && \
curl http://archive.apache.org/dist/hadoop/common/hadoop-${HADOOP_VERSION}/hadoop-${HADOOP_VERSION}.tar.gz | \
tar -zx hadoop-${HADOOP_VERSION}/lib/native && \
ln -s hadoop-${HADOOP_VERSION} hadoop && \
echo Hadoop ${HADOOP_VERSION} native libraries installed in /opt/hadoop/lib/native
# download and install spark
RUN mkdir -p /opt && \
cd /opt && \
curl http://archive.apache.org/dist/spark/spark-${SPARK_VERSION}/spark-${SPARK_VERSION}-bin-hadoop2.7.tgz | \
tar -zx && \
ln -s spark-${SPARK_VERSION}-bin-hadoop2.7 spark && \
echo Spark ${SPARK_VERSION} installed in /opt
# add scripts and update spark default config
ADD common.sh spark-master spark-worker /
ADD spark-defaults.conf /opt/spark/conf/spark-defaults.conf
ENV PATH $PATH:/opt/spark/bin
When I deploy the pods I got an error,
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning Failed 25m (x5 over 26m) kubelet Error: failed to start container "spark-master": Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/spark-master": permission denied: unknown
The contents of the script spark-master,
#!/bin/bash
. /common.sh
echo "$(hostname -i) spark-master" >> /etc/hosts
/opt/spark/bin/spark-class org.apache.spark.deploy.master.Master --ip spark-master --port 7077 --webui-port 8080
Please help to solve this issue.
My Docker Version is:
Docker version 20.10.18, build b40c2f6

In the Dockerfile I have commented out the following line
#ADD common.sh spark-master spark-worker /
Replaced the line with the below lines which resolved the permission error
COPY common.sh spark-master spark-worker /
RUN chmod +x /common.sh /spark-master /spark-worker

The contents of the script spark-master are as follows:
#!/bin/bash
. /common.sh
echo "$(hostname -i) spark-master" >> /etc/hosts
/opt/spark/bin/spark-class org.apache.spark.deploy.master.Master --ip spark-master --p spark-master-ui-port >> /var/log/spark-master.log 2>&1

Related

SSH into Azure web-app container running with non root user

I am running an Elastic and Kibana service within a container using an Azure Web app container service. I was keen on checking the SSH connectivity for this container using Azures Web SSH console feature. Followed the microsoft documentation for SSH into custom containers https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?pivots=container-linux#enable-ssh which shows the example of running the container as default root user.
My issue is Elasticsearch process does not run as a root user so I had to make the sshd process run as an elastic user. I was able to get the sshd process running which accepts the SSH connection from my host however the credentials I am setting in the docker file (elasticsearch:Docker!) are throwing Access Denied error.Any idea where i am going wrong here?
Dockerfile
FROM openjdk:jre-alpine
ARG ek_version=6.5.4
RUN apk add --quiet --no-progress --no-cache nodejs wget \
&& adduser -D elasticsearch \
&& apk add openssh \
&& echo "elasticsearch:Docker!" | chpasswd
# Copy the sshd_config file to the /etc/ssh/ directory
COPY startup.sh /home/elasticsearch/
RUN chmod +x /home/elasticsearch/startup.sh && \
chown elasticsearch /home/elasticsearch/startup.sh
COPY sshd_config /home/elasticsearch/
USER elasticsearch
WORKDIR /home/elasticsearch
ENV ES_TMPDIR=/home/elasticsearch/elasticsearch.tmp ES_DATADIR=/home/elasticsearch/elasticsearch/data
RUN wget -q -O - https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-${ek_version}.tar.gz \
| tar -zx \
&& mv elasticsearch-${ek_version} elasticsearch \
&& mkdir -p ${ES_TMPDIR} ${ES_DATADIR} \
&& wget -q -O - https://artifacts.elastic.co/downloads/kibana/kibana-oss-${ek_version}-linux-x86_64.tar.gz \
| tar -zx \
&& mv kibana-${ek_version}-linux-x86_64 kibana \
&& rm -f kibana/node/bin/node kibana/node/bin/npm \
&& ln -s $(which node) kibana/node/bin/node \
&& ln -s $(which npm) kibana/node/bin/npm
EXPOSE 9200 5601 2222
ENTRYPOINT ["/home/elasticsearch/startup.sh"]
startup.sh script
#!/bin/sh
# Generating hostkey
ssh-keygen -f /home/elasticsearch/ssh_host_rsa_key -N '' -t rsa
# starting sshd process
echo "Starting SSHD"
/usr/sbin/sshd -f sshd_config
# Staring the ES stack
echo "Starting ES"
sh elasticsearch/bin/elasticsearch -E http.host=0.0.0.0 & kibana/bin/kibana --host 0.0.0.0
sshd_config file
Port 2222
HostKey /home/elasticsearch/ssh_host_rsa_key
PidFile /home/elasticsearch/sshd.pid
ListenAddress 0.0.0.0
LoginGraceTime 180
X11Forwarding yes
Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
MACs hmac-sha1,hmac-sha1-96
StrictModes yes
SyslogFacility DAEMON
PasswordAuthentication yes
PermitEmptyPasswords no
PermitRootLogin yes
Subsystem sftp internal-sftp
Error i am getting
Please check and verify that your docker image supports SSH. It would appear that you have done everything correctly so one of the final troubleshooting steps left as this point is to verify that your image supports SSH to begin with.

unable to run jmx file in docker

Connected server from windows machine using cygwin
Created one docker file in server
[root#serverhost uname]# touch Dockerfile
[root#serverhost uname]# vi Dockerfile
Dockerfile:
#1
FROM artifactory.xxx.net/java:8.212.0.1557388225_openjdk_74e62a71
#2
LABEL maintainer="xxx#domain.com"
# 3
ARG JMETER_VERSION="5.2"
# 4
ENV JMETER_HOME /opt/apache-jmeter-${JMETER_VERSION}
ENV JMETER_BIN ${JMETER_HOME}/bin
ENV MIRROR_HOST http://mirrors.ocf.berkeley.edu/apache/jmeter
ENV JMETER_DOWNLOAD_URL ${MIRROR_HOST}/binaries/apache-jmeter-${JMETER_VERSION}.tgz
ENV JMETER_PLUGINS_DOWNLOAD_URL http://repo1.maven.org/maven2/kg/apc
ENV JMETER_PLUGINS_FOLDER ${JMETER_HOME}/lib/ext/
# 5
RUN apk update \
&& apk upgrade \
&& apk add ca-certificates \
&& update-ca-certificates \
&& apk add --update openjdk8-jre tzdata curl unzip bash \
&& cp /usr/share/zoneinfo/Europe/Rome /etc/localtime \
&& echo "Europe/Rome" > /etc/timezone \
&& rm -rf /var/cache/apk/* \
&& mkdir -p /tmp/dependencies \
&& curl -L --silent ${JMETER_DOWNLOAD_URL} > /tmp/dependencies/apache-jmeter-${JMETER_VERSION}.tgz \
&& mkdir -p /opt \
&& tar -xzf /tmp/dependencies/apache-jmeter-${JMETER_VERSION}.tgz -C /opt \
&& rm -rf /tmp/dependencies
# 6
RUN curl -L --silent ${JMETER_PLUGINS_DOWNLOAD_URL}/jmeter-plugins-dummy/0.2/jmeter-plugins-dummy-0.2.jar -o ${JMETER_PLUGINS_FOLDER}/jmeter-plugins-dummy-0.2.jar
RUN curl -L --silent ${JMETER_PLUGINS_DOWNLOAD_URL}/jmeter-plugins-cmn-jmeter/0.5/jmeter-plugins-cmn-jmeter-0.5.jar -o ${JMETER_PLUGINS_FOLDER}/jmeter-plugins-cmn-jmeter-0.5.jar
# 7
ENV PATH $PATH:$JMETER_BIN
# 8
COPY launch.sh /
#9
WORKDIR ${JMETER_HOME}
#10
ENTRYPOINT ["/launch.sh"]
Created launch.sh file in same folder where docker is created
[root#serverhost uname]# touch launch.sh
[root#serverhost uname]# vi launch.sh
launch.sh file
#!/bin/bash
set -e
freeMem=`awk '/MemFree/ { print int($2/1024) }' /proc/meminfo`
s=$(($freeMem/10*8))
x=$(($freeMem/10*8))
n=$(($freeMem/10*2))
export JVM_ARGS="-Xmn${n}m -Xms${s}m -Xmx${x}m"
echo "START Running Jmeter on `date`"
echo "JVM_ARGS=${JVM_ARGS}"
echo "jmeter args=$#"
# Keep entrypoint simple: we must pass the standard JMeter arguments
jmeter $#
echo "END Running Jmeter on `date`"
Built the docker and tagged it
[root#serverhost uname]# docker build .
[root#serverhost uname]# docker tag 090847728937 jmautomation:1.0
exit from server and copied my local jmx file folder to server
uname#QINDW191 /cygdrive/c/jmeter/$ scp -r jmeterscript uname#serverhost:~/
[uname#serverhost~]$ ls -lrt
total 12
-rw-r--r--. 1 root root 1678 Nov 26 10:29 Dockerfile
-rw-r--r--. 1 root root 331 Nov 26 11:00 launch.sh
drwxrwx---. 2 uname uname 4096 Nov 28 09:17 jmeterscript
Running jmx file in docker by copying folder to docker mnt/jmeter folder and running jmx file from there:
[root#serverhost uname]# docker run -v /home/uname/jmeterscript:/mnt/jmeter jmautomation:1.0 -n -Jenv=devint -t /mnt/jmeter/api_regression.jmx -l /mnt/jmeter/result.xml
[root#serverhost uname]# docker run --volume "/home/uname/jmeterscript":/mnt/jmeter jmautomation:1.0 -n -Jenv=devint -t /mnt/jmeter/api_regression.jmx -l /mnt/jmeter/result.xml
[root#serverhost uname]# docker run --volume "/home/uname/jmeterscript":/mnt/jmeter jmautomation:1.0 -n -Jenv="devint" -t /mnt/jmeter/api_regression.jmx -l /mnt/jmeter/result.xml
[root#serverhost uname]# docker run --volume "/home/uname/jmeterscript":/mnt jmautomation:1.0 -n -Jenv=devint -t /mnt/api_regression.jmx -l /mnt/result.xml
Tried to run with all above commands every time I am facing below error
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"-n\": executable file not found in $PATH": unknown.
ERRO[0001] error waiting for container: context canceled
Can anyone please help me what I am missing?

Docker build Gentoo operation not permitted

I have a docker-compose with this container to build Gentoo
default:
build: docker/gentoo
hostname: default.jpo.net
My Dockerfile to setup Gentoo in multi-stage build is
FROM gentoo/portage as portage
FROM gentoo/stage3-amd64
COPY --from=portage /usr/portage /usr/portage
RUN emerge --jobs $(nproc) -qv www-servers/apache net-misc/curl net-misc/openssh
RUN /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
RUN /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
RUN sed -i 's/#PubkeyAuthentication/PubkeyAuthentication/' /etc/ssh/sshd_config
RUN mkdir -p /root/.ssh && chmod 700 /root/.ssh && touch /root/.ssh/authorized_keys
RUN wget -O telegraf.tar.gz http://get.influxdb.org/telegraf/telegraf-0.11.1-1_linux_amd64.tar.gz \
&& tar xvfz telegraf.tar.gz \
&& rm telegraf.tar.gz \
&& mv /usr/lib/telegraf /usr/lib64/telegraf \
&& rm -rf /usr/lib && ln -s /usr/lib64 /usr/lib
ADD telegraf.conf /etc/telegraf/telegraf.conf
COPY entrypoint.sh /
COPY infinite_curl.sh /
RUN chmod u+x /entrypoint.sh /infinite_curl.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["telegraf", "-config", "/etc/telegraf/telegraf.conf"]
The problem is the build fail during the emerge command when it setup packages.
Then I get this error
PermissionError: [Errno 1] Operation not permitted
* ERROR: dev-libs/apr-1.5.2::gentoo failed (install phase):
* dodoc failed
I tried adding privileged=true in my docker-compose file and with adding USER root inside my Dockerfile without success.
I also tried to use the last version of openssh without success too.
I searched the Internet but I haven't found anything successfull.
Docker version
Docker version 17.12.0-ce, build c97c6d6
Docker-compose version
docker-compose version 1.18.0, build 8dd22a9
I'm on Ubuntu 16.04 and this build work well on Ubuntu 17.10 with same docker/docker-compose versions
Do you have some clues ?
Looking at in src-install() for that ebuild, this appears to be a bug upstream.
# Prallel install breaks since apr-1.5.1
#make -j1 DESTDIR="${D}" install || die
There are several two bugs related to building apr in parallel.

Docker. Exec npm command in different folder

I want to run npm install command in container.
But simple: docker exec container npm install is not the right thing for me.
I want to run this command in /home/client but my working directory in container is /home
Is that possible?
I don't want to enter container and I don't want to change working environment.
Edit 1
Dockerfile:
FROM ubuntu:16.04
COPY . /home
WORKDIR /home
RUN apt-get update && apt-get install -y \
python-pip \
postgresql \
rabbitmq-server \
libpq-dev \
python-dev \
npm \
mongodb
RUN pip install -r requirements.txt
Docker run command:
docker run \
-tid \
-p 8000:8000 \
-v $(PWD):/home \
--name container \
-e DB_NAME \
-e DB_USER \
-e DB_USER_PASSWORD \
-e DB_HOST \
-e DB_PORT \
container
Two commands in order to prove there is a directory /home/client:
docker exec container pwd
Gives: /home
docker exec container ls client
Gives:
node_modules
package.json
src
webpack.config.js
That's node modules from my host.
Edit 2
When run:
docker exec container cd /home/client
It produces the following error:
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"cd\": executable file not found in $PATH"
That is possible with:
docker exec {container} sh -c "cd /home/client && npm install"
Thanks to Matt
Yeah, it's possible. You can do it one of two ways.
Method 1
Do it in a single command like this:
$ docker exec container sh -c "cd /home/client && npm install"
Or like this (as an arg to npm install):
$ docker exec container npm install --prefix /home/client
Method 2
Use an interactive terminal:
$ docker exec -it container /bin/bash
# cd /home/client
# npm install

link command hangs when linking container to itself

Attempting to use a Docker image I built for myself for Apache Spark bernieai/docker-spark. I found that when I tried to run a script included in the container, Java threw an exception because the name of the container, spark_master, could not be found.
The root cause of this problem is that I'm trying to run Spark inside my Docker container via the script ./start-master.sh, but it throws the following error:
Caused by: java.net.UnknownHostException: spark_master
So I Googled the problem and followed the advice here: https://groups.google.com/forum/#!topic/docker-user/d-yuxRlO0yE
The problem is when I ran the command:
docker run -d -t -P --name spark_master --link spark_master:spark_master bernieai/docker-spark
Docker suddenly hung and the Daemon became unresponsive. There's no error, just hanging.
Any ideas what's wrong? Is there a better way to solve the root cause?
Added Dockerfile
############################################################
# Dockerfile for a Apache Spark Development Environment
# Based on Ubuntu Image
############################################################
FROM ubuntu:latest
MAINTAINER Justin Long <crockpotveggies.com>
ENV SPARK_VERSION 1.6.1
ENV SCALA_VERSION 2.11.7
ENV SPARK_BIN_VERSION $SPARK_VERSION-bin-hadoop2.6
ENV SPARK_HOME /usr/local/spark
ENV SCALA_HOME /usr/local/scala
ENV PATH $PATH:$SPARK_HOME/bin:$SCALA_HOME/bin
# Update the APT cache
RUN sed -i.bak 's/main$/main universe/' /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y
# Install and setup project dependencies
RUN apt-get install -y curl wget git
RUN locale-gen en_US en_US.UTF-8
#prepare for Java download
RUN apt-get install -y python-software-properties
RUN apt-get install -y software-properties-common
#grab oracle java (auto accept licence)
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java8-installer
# Install Scala
RUN wget http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz && \
tar -zxf /scala-$SCALA_VERSION.tgz -C /usr/local/ && \
ln -s /usr/local/scala-$SCALA_VERSION $SCALA_HOME && \
rm /scala-$SCALA_VERSION.tgz
# Installing Spark for Hadoop
RUN wget http://d3kbcqa49mib13.cloudfront.net/spark-$SPARK_BIN_VERSION.tgz && \
tar -zxf /spark-$SPARK_BIN_VERSION.tgz -C /usr/local/ && \
ln -s /usr/local/spark-$SPARK_BIN_VERSION $SPARK_HOME && \
rm /spark-$SPARK_BIN_VERSION.tgz
ADD scripts/start-master.sh /start-master.sh
ADD scripts/start-worker /start-worker.sh
ADD scripts/spark-shell.sh /spark-shell.sh
ADD scripts/spark-defaults.conf /spark-defaults.conf
ADD scripts/remove_alias.sh /remove_alias.sh
ENV SPARK_MASTER_OPTS="-Dspark.driver.port=7001 -Dspark.fileserver.port=7002 -Dspark.broadcast.port=7003 -Dspark.replClassServer.port=7004 -Dspark.blockManager.port=7005 -Dspark.executor.port=7006 -Dspark.ui.port=4040 -Dspark.broadcast.factory=org.apache.spark.broadcast.HttpBroadcastFactory"
ENV SPARK_WORKER_OPTS="-Dspark.driver.port=7001 -Dspark.fileserver.port=7002 -Dspark.broadcast.port=7003 -Dspark.replClassServer.port=7004 -Dspark.blockManager.port=7005 -Dspark.executor.port=7006 -Dspark.ui.port=4040 -Dspark.broadcast.factory=org.apache.spark.broadcast.HttpBroadcastFactory"
ENV SPARK_MASTER_PORT 7077
ENV SPARK_MASTER_WEBUI_PORT 8080
ENV SPARK_WORKER_PORT 8888
ENV SPARK_WORKER_WEBUI_PORT 8081
EXPOSE 8080 7077 8888 8081 4040 7001 7002 7003 7004 7005 7006
Run with -h flag. It will set the hostname to spark_master.
docker run -it --rm --name spark_master -h spark_master bernieai/docker-spark ./start-master.sh
Here is the output
starting org.apache.spark.deploy.master.Master, logging to /usr/local/spark/logs/spark--org.apache.spark.deploy.master.Master-1-spark_master.out
root#spark_master:/# tail usr/local/spark/logs/spark--org.apache.spark.deploy.master.Master-1-spark_master.out
16/04/10 03:12:04 INFO SecurityManager: Changing modify acls to: root
16/04/10 03:12:04 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users with view permissions: Set(root); users with modify permissions: Set(root)
16/04/10 03:12:05 INFO Utils: Successfully started service 'sparkMaster' on port 7077.
16/04/10 03:12:05 INFO Master: Starting Spark master at spark://spark_master:7077
16/04/10 03:12:05 INFO Master: Running Spark version 1.6.1
16/04/10 03:12:06 INFO Utils: Successfully started service 'MasterUI' on port 8080.
16/04/10 03:12:06 INFO MasterWebUI: Started MasterWebUI at http://172.17.0.2:8080
16/04/10 03:12:06 INFO Utils: Successfully started service on port 6066.
16/04/10 03:12:06 INFO StandaloneRestServer: Started REST server for submitting applications on port 6066
16/04/10 03:12:06 INFO Master: I have been elected leader! New state: ALIVE

Resources