japp.jar is not found when building docker image - java

I'm very much new to docker. I have a node application that process/read a java file. I'm trying to create a docker image that runs node and java. I node configs are working well but I'm always getting errors when building the docker file because of java - it shows
failed to compute cache key: "/japp.jar" not found: not found"
My Dockerfile contains:
FROM node:14.18.1
RUN apt-get update && apt-get -y upgrade
WORKDIR /code
EXPOSE 8443
COPY package.json /code/package.json
RUN npm install
COPY . /code
# Jave Config
FROM eclipse-temurin:11
RUN mkdir /opt/app
COPY japp.jar /opt/app
ENTRYPOINT ["java", "-jar", "/opt/app/japp.jar"]
CMD ["node","app.js"]
I was trying to follow the docs here but no luck.
In the past, I was using the following for Java config and that was working fine, but it shows some vulnerability so I need to switch to eclipse-temurin:11
# RUN echo 'deb http://ftp.debian.org/debian stretch-backports main' | tee /etc/apt/sources.list.d/stretch-backports.list
# RUN apt-get update && apt-get -y upgrade && \
# apt-get install -y openjdk-11-jre-headless && \
# apt-get clean;

Related

Syntax error: "(" unexpected when running Docker container

This is my Dockerfile:
# Setup Inst
FROM ubuntu:latest
MAINTAINER test
LABEL maintainer="test"
RUN mkdir /srv/papermc
WORKDIR /srv/papermc
# Install OpenJDK-17
RUN apt-get update && \
apt-get install -y openjdk-17-jre-headless && \
apt-get install -y ant && \
apt-get install -y screen && \
apt-get install -y wget && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f;
# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64/
RUN export JAVA_HOME
# Download PAPERMINECRAFT
RUN wget https://api.papermc.io/v2/projects/paper/versions/1.19.3/builds/363/downloads/paper-1.19.3-363.jar
# STOP
STOPSIGNAL SIGTERM
# ENV
ENV TYPE=VANILLA VERSION=1.19.3 EULA="" UID=1000 GID=1000 RCON_PASSWORD=paper
# Prepare RUN
EXPOSE 25565 25575
VOLUME /srv/papermc
RUN echo "screen -AmdS minecraft java -Xms1024M -Xmx1024M -jar /srv/mcvanilla/paper-1.19.2-220.jar nogui" > start
RUN chmod -R 775 /srv/papermc
ENTRYPOINT ["/bin/sh"]
CMD start
HEALTHCHECK none
It is building without errors, but if I try to start the container, I get the following error:
Successfully tagged papermc:latest
root#docker3:~# docker run papermc
/bin/sh: 2: Syntax error: "(" unexpected
I was expecting a Java error because of not accepting the EULA, but not this one. What could be wrong?
Your ENTRYPOINT/CMD setup is wrong. You should simplify the end of the file to
# ...do the installation steps...
ENV TYPE=VANILLA VERSION=1.19.3 EULA="" UID=1000 GID=1000 RCON_PASSWORD=paper
CMD java -Xms1024M -Xmx1024M -jar /srv/mcvanilla/paper-1.19.2-220.jar nogui
and then docker run papermc will start the server without requiring you to log in, start a screen session, or anything else.
As #CharlesDuffy hints in a comment, if you're just wrapping a single process, Docker and Screen have some similarities and it's unusual to use Screen in a container. You can view the docker logs of the container and, in the unusual event you need to interact with the process's stdin, docker attach to it.
What's actually happening in your case deals with the way string-form CMD is converted to an actual command-word array and then combined with ENTRYPOINT. The documentation on Dockerfile ENTRYPOINT has details on these mechanics. As you've written it, the single command the container runs is
/bin/sh /bin/sh -c 'start'
which in turn causes the shell to try to execute the /bin/sh binary as a shell script, passing it arguments -c and start as the positional variables $1 and $2. When /bin/sh is an ELF binary and not itself a shell script, you get a parse error like this.

Selenium inside Docker image for Java application

I've developped Java application to make some litle web scraping tasks with Selenium.
It work fine in my local environment with Windows 10 and both chrome / FireFox last versions with their appropriate driver path configured.
The thing is I need my application to be in a container to deploy it and I've got issues.
I've created a Dockerfile based on Alpine, and installed what need to be installed (helped by some posts found on the internet). With the FireFox driver it's working almost fine for the first operations but some do not work the same as they do in my configuration in local and some even crash the client... That's why I've tried with chromium but I've got some issues with a connection to the browser not even working.
I've spent hours already on this and start thinking maybe I'm missing something, am I supposed to do that way by dowloading browsers and driver in my Dockerfile ?
For now I sucpect the versions of FireFox or the geckodriver associated not behaving the same as the one I've got on my machine and I can see the browser when It's working inside the container only logs I've added.
Dockerfile (for FireFox browser try) :
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
# https://stackoverflow.com/questions/58738920/running-geckodriver-in-an-alpine-docker-container
# Get all the prereqs
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-2.34-r0.apk
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-bin-2.34-r0.apk
RUN apk add glibc-2.34-r0.apk
RUN apk add glibc-bin-2.34-r0.apk
# And of course we need Firefox if we actually want to *use* GeckoDriver
RUN apk add firefox-esr=60.9.0-r0
# Then install GeckoDriver
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.29.1/geckodriver-v0.29.1-linux64.tar.gz
RUN tar -zxf geckodriver-v0.29.1-linux64.tar.gz -C /usr/bin
ENTRYPOINT ["java","-jar","/app.jar"]
Dockerfile (for Chrome browser try, I know optimisations could be made probably) :
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
RUN apk update && apk add --no-cache bash \
alsa-lib \
at-spi2-atk \
atk \
cairo \
cups-libs \
dbus-libs \
eudev-libs \
expat \
flac \
gdk-pixbuf \
glib \
libgcc \
libjpeg-turbo \
libpng \
libwebp \
libx11 \
libxcomposite \
libxdamage \
libxext \
libxfixes \
tzdata \
libexif \
udev \
xvfb \
zlib-dev \
chromium \
chromium-chromedriver
ENTRYPOINT ["java","-jar","/app.jar"]
Maybe I should use a docker image like https://hub.docker.com/r/selenium/standalone-firefox and install Java manually instead ?
I'm very frustrated by could not being able to reproduce my local behavior inside the container and I would really appreciate some help on this ! I don't want to give up :)
Indeed Jortega I've based my image on the selenium image : https://hub.docker.com/r/selenium/standalone-firefox
Here is my Dockerfile
FROM selenium/standalone-firefox:91.0-20210823
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
# Spring boot entrypoint
ENTRYPOINT ["java","-jar","/app.jar"]
In my Java application here's the FireFox configuration :
// webBrowserDriverPath is a env variable set to "/usr/bin/geckodriver"
System.setProperty("webdriver.gecko.driver", webBrowserDriverPath);
final FirefoxOptions options = new FirefoxOptions();
options.addArguments(
"--no-sandbox",
"--disable-extensions",
"--disable-gpu",
"--window-size=1920,1200",
"--ignore-certificate-errors",
"--whitelisted-ips=''",
"--disable-dev-shm-usage",
"--window-size=1920,1080",
"--lang=fr");
// display browser in dev mode
if (conf.isHeadlessModeEnabled()) {
options.addArguments("--headless");
}
options.addPreference("intl.accept_languages", "fr");
this.remoteWebDriver = new FirefoxDriver(options);
Everything work fine !
I am using this docker setup for my automation, working fine. link
i am using following option,
options.addArguments(Arrays.asList("--window-position=0,0"));
options.addArguments(Arrays.asList("--window-size=1840,1080"));
driver = new RemoteWebDriver(new URL(hub), options);
your dockerfile for Chromium (not chrome) is correct.
you have to add in java code:
chromeOptions.setBinary("/usr/bin/chromium-browser");
I have also working version: jdk 11 (ubuntu) + chrome (for selenium):
# on ubuntu
FROM azul/zulu-openjdk:11
RUN apt-get update && apt-get install -y \
gnupg2 \
wget \
less \
&& rm -rf /var/lib/apt/lists/*
#######################
# Google Chrome
# Adding trusting keys to apt for repositories
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub |
apt-key add -
# Adding Google Chrome to the repositories
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/
stable main" >> /etc/apt/sources.list.d/google-chrome.list'
# Updating apt to see and install Google Chrome
RUN apt-get -y update
# Magic happens
RUN apt-get install -y google-chrome-stable
# Installing Unzip
RUN apt-get install -yqq unzip
#######################
# Google Chrome Driver - now i have driver in my java app (i need both
java app version on docker and non-docker)
# Download the Chrome Driver
#RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub |
apt-key add -
#RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/
stable main" >> /etc/apt/sources.list.d/google-chrome.list'
#RUN apt-get -y update
#RUN apt-get install -y google-chrome-stable
# install chromedriver
#RUN apt-get install -yqq unzip
#RUN wget -O /tmp/chromedriver.zip
http://chromedriver.storage.googleapis.com/`curl -sS
chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
#RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
#######################
RUN apt-get update
# Set display port as an environment variable
ENV DISPLAY=:99
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} bot-app.jar
ENTRYPOINT ["java","-jar","/bot-app.jar"]
It works fine.

disconnected from airflow docker container after ~10 s

I successfully created and started this container :
https://github.com/puckel/docker-airflow
by running :
docker build --rm --build-arg AIRFLOW_DEPS="datadog,dask" --build-arg PYTHON_DEPS="flask_oauthlib>=0.9" -t puckel/docker-airflow .
docker-compose -f docker-compose-CeleryExecutor.yml up -d
Then i just wanted to add java to images :
I added at the end :
https://github.com/puckel/docker-airflow/blob/master/Dockerfile#L83
USER airflow
WORKDIR ${AIRFLOW_USER_HOME}
ENTRYPOINT ["/entrypoint.sh"]
CMD ["webserver"] # set default arg for entrypoint
# my new code :
USER root
RUN mkdir -p /usr/share/man/man1/
# Install OpenJDK-8
RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f;
# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
After building and running the container,
i'm trying to connect like i did before instaling java :
docker exec -it docker-airflow_worker_1 /bin/bash
But i'm automaticaly disconnected. And java is installed
root#5475d28fb5f5:/usr/local/airflow# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-8u232-b09-1~deb9u1-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
root#5475d28fb5f5:/usr/local/airflow# %
And when i log the container :
User information: uid=0 euid=0 gid=0 egid=0
[2019-10-31 12:07:40,312] {{settings.py:213}} INFO - settings.configure_orm(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=1
/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
[2019-10-31 12:07:40,621] {{__init__.py:51}} INFO - Using executor CeleryExecutor
Running a worker with superuser privileges when the
worker accepts messages serialized with pickle is a very bad idea!
If you really want to continue then you have to set the C_FORCE_ROOT
environment variable (but please think about this before you do).
User information: uid=0 euid=0 gid=0 egid=0
Can anyone help ?
Thanks
So you changed user to root in Dockerfile and Airflow now refuses to start. Try to move your new code in Dockerfile before USER airflow line. Also you can delete USER root line after that.

How do I put Java onto a Ubuntu docker container?

I currently have a docker container with an Ubuntu(17.10) image installed with other packages included. However, I'm currently having difficulty trying to install Java onto this container in addition to the current image.
Current Dockerfile :
FROM cityofzion/neo-privatenet
ADD files/ files/
ENTRYPOINT [ "/bin/bash" ]
When trying to find information on how to do this and testing inside of the container most suggest using this command: apt-get install -y oracle-java9-installer
However this results in:E: Unable to locate package oracle-java9-installer
I have also tried this suggested command wget http://download.java.net/java/GA/jdk9/9/binaries/jdk-9+181_linux-x64_bin.tar.gz
Which produces this result HTTP request sent, awaiting response...
404 Not Found - ERROR 404: Not Found.
I have only tried running these commands in the container, since that is how they would be run and they seem to be failing.
Can anyone suggest what I can include into my Dockerfile that install java onto my image?
Thanks in advance.
You can also directly pull any of the open-jdk images mentioned at (https://hub.docker.com/_/openjdk/) and use it. There is no need to install Ubuntu in docker image and then install Java on top of it. These images already use Ubuntu (with bare-minimum file system).
add to to your docker file
RUN \
apt-get update && \
apt-get install -y software-properties-common && \
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get update && \
apt-get install -y oracle-java9-installer && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/oracle-jdk8-installer
ENV JAVA_HOME /usr/lib/jvm/java-9-oracle
Following from here
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Oracle JDK version 7
sudo apt-get install oracle-java7-installer
Oracle JDK version 8
sudo apt-get install oracle-java8-installer

How to split docker file from monolithic deployment

In a single docker file I use to run Node and Java for the following:
run test script
run java executable (to bundle screenshots)
run my application
My understanding from the documentation is that this is bad practice, in the sense that this is a 'monolithic' deployment. I am supposed to split this in separate images based on the individual tasks. So, presumably, I would have 3 docker files.
Dockerfile 1: test script
FROM node:8
RUN node --version
RUN apt-get update && apt-get install -yq libgconf-2-4
# Note: this installs the necessary libs to make the bundled version of Chromium work
RUN apt-get update && apt-get install -y wget --no-install-recommends \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y curl \
&& rm -rf /src/*.deb
# project repo
RUN git clone ...
WORKDIR /myApp/
RUN npm install
RUN npm i puppeteer
CMD ["node", "test.ts"]
Dockerfile 2: Java executable (bundle images)
FROM openjdk
RUN git clone -b ...
WORKDIR /myApp/
CMD ["java -jar", "ImageTester.jar"]
Dockerfile 3: Run app
FROM node:8
RUN node --version
RUN git clone -b ...
WORKDIR /myApp/
RUN npm install
EXPOSE 9999
CMD ["npm", "start"]
The question is, how does one exactly do this? How is a non monolithic deployment implemented in my case? How does one run 3 docker images inside one project?
Use docker-compose. In your docker-compose.yml file, you'll have 3 services pointing to the 3 different dockerfiles.
Ex:
version: '3'
services:
test:
build:
context: .
dockerfile: Dockerfile.test
images:
build:
context: .
dockerfile: Dockerfile.images
app:
build:
context: .
dockerfile: Dockerfile.app

Categories