Couldn't find an alternative telinit implementation to spawn in DOCKER while starting MarkLogic application in CENTOS7 - docker

I am running a docker file in windows 11 which will do two operations by running two scripts parallelly. So there are 2 bash scripts to do these 2 operations-
Install an application MarkLogic in CentOS7 (marklogicinstall.sh)
Deploy some files in the application server (deploy.sh)
I have written a wrapper script which commands to first run the script1, then the second1
However, I get this below error where the first script ends and before the second one starts-
Couldn't find an alternative telinit implementation to spawn.
The installation script which is marklogicinstall.sh is like this -
#!/bin/bash
# Get any CentOS updates then clear the Docker cache
#install yum by rpm
#yum -y update && yum clean all
# Install MarkLogic dependencies
yum -y install glibc.i686 gdb.x86_64 redhat-lsb.x86_64 && yum clean all
# Install the initscripts package so MarkLogic starts ok
yum -y install initscripts && yum clean all
# Install MarkLogic then delete the .RPM file if the install succeeded
yum -y install MarkLogic.rpm && rm MarkLogic.rpm
printf "Marklogic installation done"
# Set the Path
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/MarkLogic/mlcmd/bin"
exec /usr/sbin/init
service /etc/init.d/MarkLogic start
Is it a problem with the start command?

Related

issue in creating docker image from docker file

Created a Docker file in oreder to install Tomcat server from Unix as bashe os
My Dockerfile:
FROM ubuntu
RUN apt-get update && apt-get upgrade -y #to update os
RUN apt-get dist-upgrade
RUN apt-get install build-essential
RUN apt-get install openjdk-8-jdk # to install java 8
RUN apt-get wget -y #to install wget package
RUN apt-get wget https://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz #to download tomcat
RUN tar -xvzf apache-tomcat-9.0.37 # unzipping the tomcat
RUN mkdir tomcat # craeting tomacat directory
RUN cp apache-tomcat-9.0.37/* tomcat # copying tomact files to tomact directory
Command to create Docker Image from Docker file:
docker build -t [img name] -f [file name] .
On execution, while installing java package am getting like this:
'''After this operation, 242 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y'''
You are getting the prompt because the command is awaiting user input for whether or not to install a package. The -y flag you're using for a few of them (like wget) allows bash to assume a yes. Add this flag to all your installation commands.
By the way, there's quite a few potential issues with the Dockerfile you posted.
For example, you have RUN apt-get wget ...
Are you sure that is what you want to do, and not just RUN wget ...? Unless wget is a command that apt-get takes, which it isn't, it will cause unexpected behavior.
You also seem to be missing the command to start the Tomcat server, which can make it so that nothing happens when you attempt to run the image.
I think you should add DEBIAN_FRONTEND=noninteractive when running the apt-get commands, something like this:
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install build-essential -y
Also, it's considered bad practice to use multiple RUN steps which could be consolidated into one. More about Dockerfile best practices can be found here.

Jenkins not starting in docker (Dockerfile included)

I am attempting to build a simple app with Jenkins in a docker container. I have the following Dockerfile:
FROM ubuntu:trusty
# Install dependencies for Flask app.
RUN sudo apt-get update
RUN sudo apt-get install -y vim
RUN sudo apt-get install -y curl
RUN sudo apt-get install -y python3-pip
RUN pip3 install flask
# Install dependencies for Jenkins (Java).
# Install Java 1.8.
RUN sudo apt-get install -y python-software-properties debconf-utils
RUN sudo apt-get install -y software-properties-common
RUN sudo add-apt-repository -y ppa:webupd8team/java
RUN sudo apt-get update
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
RUN sudo apt-get install -y oracle-java8-installer
# Install, start Jenkins.
RUN sudo apt-get install -y wget
RUN wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | apt-key add -
RUN echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
RUN sudo apt-get update
RUN sudo apt-get install -y jenkins
RUN sudo /etc/init.d/jenkins start
COPY ./app /app
CMD ["python3","/app/main.py"]
I run this container with the following:
docker build -t jenkins_test .
docker run --name jenkins_test_container -tid -p 5000:5000 -p 8080:8080 jenkins_test:latest
I am able to start flask and install Jenkins, however, when running, Jenkins is not running. curl localhost:8080 is not successful.
In the log output, I am able to see:
Correct java version found
* Starting Jenkins Automation Server jenkins [ OK ]
However, it's still not running.
I can ssh into the container and manually run sudo /etc/init.d/jenkins start to start it, but I want it to start on docker run or docker build.
I have also tried putting sudo /etc/init.d/jenkins start in the CMD portion of the Docker file:
CMD python3 /app/main.py; sudo /etc/init.d/jenkins start
With this, I am able to curl Flask, but still not Jenkins.
How can I get Jenkins to start automatically?
You have some points that you need to be aware of:
No need to use sudo as the default user is root already.
In order to run multiple service in the same container you need to use any kind of service manager like Supervisord. Jenkins is not running because the CMD is the main entry point for your container so only flask should be running. Check the following link in order to know how to start multiple service in docker.
RUN will be executed only during the build process unlike CMD which will be executed each time you start a container from that image.
Combine all the RUN lines together as possible in order to minimize the build layers which lead to a smaller docker image.
Regarding the usage of this:
CMD python3 /app/main.py; sudo /etc/init.d/jenkins start
It does not work for you because this command python3 /app/main.py is not running as a background process so this command sudo /etc/init.d/jenkins start wont run until the previous command is done.
I was only able to get this to work by starting Jenkins in the CMD portion, but needed to start Jenkins before Flask since Flask would continuously run and the next command would never execute:
Did not work:
CMD python3 /app/main.py; sudo /etc/init.d/jenkins start
This did work:
CMD sudo /etc/init.d/jenkins start; python3 /app/main.py
EDIT:
I believe putting it in the RUN portion would not work because container would build but not save the any running services. I'm not sure if containers can be saved and loaded with running processes like that but I might be wrong. Would appreciate clarification if so.
It seems like a thing that should be in RUN so if anyone knows why that didn't work or some best practices, would also appreciate the info.

Docker - SFTP installation

I am trying for installing SFTP in the Docker container.
I have the following in my Dockerfile. Able to install ntp this way, but failing for sftp. May I know the command?
RUN yum install -y ntp \
&& yum install -y sftp
You should add more information such as:
Linux version (if your container is a Redhat, CentOS, version...)
Command you've executed to build / run.
Error message.
Anyway, you can try with this while we wait for your additional info:
RUN yum install -y ntp \
&& yum install -y vsftpd

Run "From .." docker image inside Dockerfile

I'm building a image that builds a Jenkins and I try to use a plugin over the Jenkins when it is running, so, I need get run Jenkins before my plugin execution.
I execute it like docker build -t dockerfile and the error wich I am obtaining:
jenkins.JenkinsException: Error in request: [Errno 99]
Cannot assign requested address
I think the problem is when the plugin is executed it guess Jenkins is running and not.
FROM foxylion/jenkins
MAINTAINER Mishel Uchuari <dmuchuari#hotmail.com>
RUN /usr/local/bin/install-plugins.sh workflow-remote-loader workflow-aggregator build-pipeline-plugin
ENV JENKINS_USER replicate
ENV JENKINS_PASS replicate
USER root
RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y apt-utils
RUN apt-get install -y python-pip
RUN apt install -y linuxbrew-wrapper
RUN useradd someuser -m -s /bin/bash
USER someuser
RUN chmod -R 777 /home/someuser
RUN brew install libyaml
USER root
RUN apt-get install build-essential
RUN apt-get -y update && apt-get -y upgrade
RUN pip install jenkins-job-builder==2.0.0.0b2
RUN pip install PyYAML python-jenkins
RUN mkdir /etc/jenkins_jobs/
COPY jenkins_jobs.ini /etc/jenkins_jobs/
COPY scm_pipeline.yaml /etc/jenkins_jobs/
RUN jenkins-jobs --conf /etc/jenkins_jobs/jenkins_jobs.ini update /etc/jenkins_jobs/scm_pipeline.yaml
I had the same issue myself when using it under Docker:
File "/src/.tox/py27/local/lib/python2.7/site-packages/jenkins_jobs/builder.py", line 124, in get_plugins_info
raise e
JenkinsException: Error in request: [Errno 99] Cannot assign requested address
That was caused when it tries to retrieve the list of plugins, I went overriding plugins_info to short circuit the code path:
jjb = JenkinsJobs(args=['test', config_dir, '-o', output_dir])
jjb.builder['plugins_info'] = [] # prevents 99 cannot assign requested address
jjb.execute()
I had the issue with python 2.7.9 on Debian Jessie. If I remember correctly that is no more an issue with a later python version eg 2.7.13 from Debian Stretch.
(the patch on which I encountered the issue):
https://gerrit.wikimedia.org/r/#/c/380929/8/tests/test_integration.py
RUN brew install libyaml
brew is a package manager for Mac OS X. Also PyYAML gracefully skip compilation when the lib is not availble. So you probably do not need that one. And I guess it would work without installing build-essential.
RUN pip install jenkins-job-builder==2.0.0.0b2
RUN pip install PyYAML python-jenkins
I am surprised you have install PyYAML and python-jenkins explicitly. Supposedly installing jenkins-job-builder should install all the dependencies (eg PyYAML and python-jenkins).

How to make sure commands are not repeated in docker

I am learning about build image using docker file.
short description of what I have done
step 1
For making testing I have started on build image using below docker file
FROM centos:6.8
MAINTAINER Bilal Usean "xxxxx#xxx.xxx"
RUN yum install -y httpd; yum -y clean all
after that I have run the below command
docker build -t httpd/centos:6.8 .
it is successfully install apache in httpd/centos:6.8 image
step 2
Next I am trying to install jdk in the same existing newly created image
FROM centos:6.8
MAINTAINER Bilal Usean "xxxxxx#xxx#xx"
RUN yum install -y httpd; yum -y clean all
yum install java-1.6.0-openjdk-devel; yum -y clean all
after that I have run the below command
docker build -t httpd/centos:6.8 .
But It will start from again httpd install, I expected it will skip that httpd step for already install.
I think it is not a good practice to make docker file.I have 20 RUN command in docker file, that is download heavy size file from net so I want to make sure about it each command success. otherwise it will fail intermediately and again it will charge more MB.
note: If I am in the wrong way, please describe the best way to deal with image and docker file.
It repeats here because you did not add another RUN command, but appended (and changed) the previous command (docker detects this change, and runs the new command).
What you should be writing is:
FROM centos:6.8
MAINTAINER Bilal Usean "xxxxxxxx#xxx.xxx"
RUN yum install -y httpd; yum -y clean all
RUN yum install java-1.6.0-openjdk-devel; yum -y clean all

Resources