I wrote a dockerfile to build a clashserver in ubuntu container. However, when I tried to stop the container, the docker just got stuck. There is no any error code or any answer from the terminal.
I think some disharmony command appeared in the dockerfile.
This is my dockerfile:
FROM ubuntu:latest
RUN cp /etc/apt/sources.list /etc/apt/sources.list.backup \
&& apt-get update -y \
&& apt-get upgrade -y \
&& apt-get clean \
&& apt-get autoclean \
COPY clash-linux-amd64 /bin/clash_run
RUN mkdir /etc/clash \
&& chmod +x /bin/clash_run
EXPOSE 7890
EXPOSE 7891
EXPOSE 9090
CMD ["/bin/clash_run","-d","/etc/Clash/"]
If you want to pull the docker image:cfbsks/clash_ubuntu:v0.1
Related
I have a docker file in which I do wget to copy something in the image. But the build is failing giving 'wget command not found'. WHen i googled I found suggestions to install wget like below
RUN apt update && apt upgrade
RUN apt install wget
Docker File:
FROM openjdk:17
LABEL maintainer="app"
ARG uname
ARG pwd
RUN useradd -ms /bin/bash -u 1000 user1
COPY . /app
WORKDIR /app
RUN ./gradlew build -PmavenUsername=$uname -PmavenPassword=$pwd
ARG YOURKIT_VERSION=2021.11
ARG POLARIS_YK_DIR=YourKit-JavaProfiler-2019.8
RUN wget https://www.yourkit.com/download/docker/YourKit-JavaProfiler-${YOURKIT_VERSION}-docker.zip --no-check-certificate -P /tmp/ && \
unzip /tmp/YourKit-JavaProfiler-${YOURKIT_VERSION}-docker.zip -d /usr/local && \
mv /usr/local/YourKit-JavaProfiler-${YOURKIT_VERSION} /usr/local/$POLARIS_YK_DIR && \
rm /tmp/YourKit-JavaProfiler-${YOURKIT_VERSION}-docker.zip
EXPOSE 10001
EXPOSE 8080
EXPOSE 5005
USER 1000
ENTRYPOINT ["sh", "/docker_entrypoint.sh"]
On doing this I am getting error app-get not found. Can some one suggest any solution.
The openjdk image you use is based on Oracle Linux which uses microdnf rather than apt as it's package manager.
To install wget (and unzip which you also need), you can add this to your Dockerfile:
RUN microdnf update \
&& microdnf install --nodocs wget unzip \
&& microdnf clean all \
&& rm -rf /var/cache/yum
The commands clean up the package cache after installing, to keep the image size as small as possible.
I installed Elasticsearch in my image based on ubuntu:16.04.
And start the service using
RUN service elasticsearch start
but, it was not started.
If I go into the container and run it, it starts.
I want to run the service and dump the index when I create the image, below is a part of my Dockerfile.
How do I start Elasticsearch in the Dockerfile?
#install OpenJDK-8
RUN apt-get update && apt-get install -y openjdk-8-jdk && apt-get install -y ant && apt-get clean
RUN apt-get update && apt-get install -y ca-certificates-java && apt-get clean
RUN update-ca-certificates -f
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
#download ES
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN apt-get install -y apt-transport-https
RUN echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-6.x.list
RUN apt-get update && apt-get install -y elasticsearch
RUN service elasticsearch start
The RUN command executes only during the build phase. It stops after the build is completed. You should use CMD (or ENTRYPOINT) instead:
CMD service elasticsearch start && /bin/bash
It's better wrapping the starting command in your own file and then only execute the file:
CMD /start_elastic.sh
I don't know why not take official oss image, but, this Docker file based on Debian work:
FROM java:8-jre
ENV ES_NAME=elasticsearch \
ELASTICSEARCH_VERSION=6.6.1
ENV ELASTICSEARCH_URL=https://artifacts.elastic.co/downloads/$ES_NAME/$ES_NAME-$ELASTICSEARCH_VERSION.tar.gz
RUN apt-get update && apt-get install -y --assume-yes openssl bash curl wget \
&& mkdir -p /opt \
&& echo '[i] Start create elasticsearch' \
&& wget -T 15 -O /tmp/$ES_NAME-$ELASTICSEARCH_VERSION.tar.gz $ELASTICSEARCH_URL \
&& tar -xzf /tmp/$ES_NAME-$ELASTICSEARCH_VERSION.tar.gz -C /opt/ \
&& ln -s /opt/$ES_NAME-$ELASTICSEARCH_VERSION /opt/$ES_NAME \
&& useradd elastic \
&& mkdir -p /var/lib/elasticsearch /opt/$ES_NAME/plugins /opt/$ES_NAME/config/scripts \
&& chown -R elastic /opt/$ES_NAME-$ELASTICSEARCH_VERSION/
ENV PATH=/opt/elasticsearch/bin:$PATH
USER elastic
CMD [ "/bin/sh", "-c", "/opt/elasticsearch/bin/elasticsearch --E cluster.name=test --E network.host=0 $ELASTIC_CMD_OPTIONS" ]
I believe most of the commands you'll be able to use on Ubuntu.
Don't forget to run sudo sysctl -w vm.max_map_count=262144 on your host
I need to build the dockerfile that downloads jenkins.war and through it jenkins-cli.jar need to be downloaded.
I have conf.xml also to configure it.**
Then I need that image to run in the bash, which needs to run that jar file commands.
Here is the code:
FROM ubuntu:14.04
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:webupd8team/java -y && \
apt-get update && \
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
apt-get install -f -y oracle-java8-installer && \
apt install -y default-jre curl wget git nano; \
apt-get clean
# Install dependencies
RUN apt-get -y update && \
apt-get -yqq --no-install-recommends install git bzip2 curl unzip && \
apt-get update
ENV JAVA_HOME /usr
ENV PATH $JAVA_HOME/bin:$PATH
# copy jenkins war file to the container
ADD http://mirrors.jenkins.io/war-stable/2.107.1/jenkins.war /opt/jenkins.war
RUN chmod 644 /opt/jenkins.war
ENV JENKINS_HOME /jenkins
# configure the container to run jenkins, mapping container port 8080 to that host port
RUN mkdir /jenkins/
RUN echo 2.107.1 > /jenkins/jenkins.install.UpgradeWizard.state
RUN echo 2.107.1 > /jenkins/jenkins.install.InstallUtil.lastExecVersion
CMD ["nohup","java", "-jar", "/opt/jenkins.war"]
EXPOSE 8080
VOLUME /jenkins
#COPY jenkins-cli.jar /jenkins/jenkins-cli.jar
#jenkins-cli installation
ENV JENKINS_URL "http://192.168.99.100:8080"
RUN curl --insecure http://192.168.99.100:8080/jnlpJars/jenkins-cli.jar \
--output /jenkins/jenkins-cli.jar
CMD ["java","-jar","/jenkins/jenkins-cli.jar","-noCertificateCheck","-noKeyAuth"]
Here is what im getting.
MY ASSUMPTION
Do I need to run along congf.xml?If yes , then HOW?
Do I need to be running jenkins.war instance in background??? HOW?
Thank you in advance
If you see the reference , I can find those comments.
There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.
in your dockerfile, there are multiple CMD commands. only the last one will be executed.
If you want to run multiple commands at once. try bash scripts. here is the example
#!/bin/bash
echo "Starting sshd"
exec /usr/sbin/sshd -D &
if [ -z "$1" ];
then
tail -f $HADOOP_INSTALL/logs/*
fi
i need a container running with java installed in it and i want to expose the port 8090.
Here is the Docker file i have written to achieve this.
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive
ENV VERSION 8
ENV UPDATE 152
ENV BUILD 16
ENV SIG aa0333dd3019491ca4f6ddbe78cdb6d0
ENV JAVA_HOME /usr/lib/jvm/java-${VERSION}-oracle
# install jre
RUN apt-get update -qq && \
apt-get upgrade -qqy --no-install-recommends && \
apt-get install curl unzip bzip2 -qqy && \
mkdir -p "${JAVA_HOME}" && \
curl --silent --location --insecure --junk-session-cookies --retry 3 \
--header "Cookie: oraclelicense=accept-securebackup-cookie;" \
http://download.oracle.com/otn-pub/java/jdk/"${VERSION}"u"${UPDATE}"-b"${BUILD}"/"${SIG}"/jre-"${VERSION}"u"${UPDATE}"-linux-x64.tar.gz \
| tar -xzC "${JAVA_HOME}" --strip-components=1 && \
apt-get remove --purge --auto-remove -y curl unzip bzip2 && \
apt-get autoclean && apt-get --purge -y autoremove && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN update-alternatives --install "/usr/bin/java" "java" "${JAVA_HOME}/bin/java" 1 && \
update-alternatives --install "/usr/bin/javaws" "javaws" "${JAVA_HOME}/bin/javaws" 1 && \
update-alternatives --set java "${JAVA_HOME}/bin/java" && \
update-alternatives --set javaws "${JAVA_HOME}/bin/javaws"
EXPOSE 8090
Using the Dockerfile i was able to successfully build the image and i have pushed to my account in hub.docker.com
but when i run try to run the container using the following command , The Container was not running.
i broked my head analyzing the root cause more than 2 hours i was not able to find the problem.
I know i am missing something silly, can anyone have a look and point the mistake i am doing?
Thanks in advance
Your Dockerfile is missing an ENTRYPOINT or CMD instruction. They define what command is run when starting the container.
Reference CMD
Reference ENTRYPOINT
You didn't define a ENTRYPOINT or CMD.
Some useful links:
What is the difference between CMD and ENTRYPOINT in a Dockerfile?
https://www.ctl.io/developers/blog/post/dockerfile-entrypoint-vs-cmd/
https://docs.docker.com/engine/reference/builder/#known-issues-run
I tried Apache for ubuntu in Docker (Docker for windows) in https://github.com/Paritosh-Anand/Docker-Httpd-Tomcat
The Dockerfile is
FROM ubuntu:latest
MAINTAINER <user>#<domain>.com
RUN apt-get update && apt-get install -y --no-install-recommends apache2 libapache2-mod-jk
ADD apache2.conf /etc/apache2/apache2.conf
ADD 000-default.conf /etc/apache2/sites-enabled/000-default.conf
ADD worker.properties /etc/libapache2-mod-jk/workers.properties
ADD jk.conf /etc/apache2/mods-available/jk.conf
VOLUME ["/var/log/apache2"]
EXPOSE 80 443
CMD ["apachectl", "-k", "start", "-DFOREGROUND"]
However, I need to run Apache in CentOs 7, not in ubuntu. So I changed the Dockerfile to
FROM centos:7
MAINTAINER <user>#<domain>.com
RUN yum -y --setopt=tsflags=nodocs update
RUN yum -y --setopt=tsflags=nodocs install httpd
RUN yum -y --setopt=tsflags=nodocs install mod-jk
RUN yum clean all
ADD apache2.conf /etc/apache2/apache2.conf
ADD 000-default.conf /etc/apache2/sites-enabled/000-default.conf
ADD worker.properties /etc/libapache2-mod-jk/workers.properties
ADD jk.conf /etc/apache2/mods-available/jk.conf
VOLUME ["/var/log/apache2"]
EXPOSE 80 443
CMD ["apachectl", "-k", "start", "-DFOREGROUND"]
On running, I am getting the error
Step 5/13 : RUN yum -y --setopt=tsflags=nodocs install mod-jk
---> Running in a98487a9509c
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirrors.nhanhoa.com
* extras: mirrors.nhanhoa.com
* updates: mirror.ehost.vn
No package mod-jk available.
Error: Nothing to do
ERROR: Service 'httpd' failed to build: The command '/bin/sh -c yum -y --setopt=tsflags=nodocs install mod-jk' returned a non-zero code: 1
Is this a problem with mirror? How can I install mod_jk in docker where operating system is CentOs 7?
My Host operating system is windows 10
For centos 7 you will need to compile the module from source. Consider the below Dockerfile as an example
FROM centos:7
RUN yum -y update && yum clean all
RUN yum -y install httpd httpd-devel gcc* make && yum clean all
# Install mod_jk
RUN curl -SL http://mirror.sdunix.com/apache/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.40-src.tar.gz -o tomcat-connectors-1.2.40-src.tar.gz \
&& mkdir -p src/tomcat-connectors \
&& tar xzf tomcat-connectors-1.2.40-src.tar.gz -C src/tomcat-connectors --strip-components=1 \
&& cd src/tomcat-connectors/native/ \
&& ./configure --with-apxs=/usr/bin/apxs \
&& make \
&& cp apache-2.0/mod_jk.so /usr/lib64/httpd/modules/ \
&& ./libtool --finish /usr/lib64/httpd/modules/ \
&& cd / \
&& rm -rf src/ \
&& rm -f tomcat-connectors-1.2.40-src.tar.gz
# mod_jk conf files
ADD mod_jk.conf /etc/httpd/conf.d/
ADD workers.properties /etc/httpd/conf.d/
EXPOSE 80
# Simple startup script to avoid some issues observed with container restart
ADD run-httpd.sh /run-httpd.sh
RUN chmod -v +x /run-httpd.sh
CMD ["/run-httpd.sh"]
Taken from https://github.com/maeharin/apache-tomcat-docker-sample/blob/master/docker/httpd/Dockerfile