I'm deploying an application to a pre-configured GlassFish Docker container on Elastic Beanstalk. I need to install the MySQL connector/J library so it's accessible to GlassFish. According to the AWS documentation, "With preconfigured Docker platforms you cannot use a configuration file to customize and configure the software that your application depends on." But it does state: "you can add a Dockerfile to your application's root folder."
They provide an example (with no explanation!) on installing a PostgreSQL library for Python but I'm using Java and MySQL. As I am completely unfamiliar with Docker (and really just need to configure this one thing), I can't figure out how to do it. Using Amazon's example Dockerfile I was able to come up with this:
FROM amazon/aws-eb-glassfish:4.1-jdk8-onbuild-3.5.1
# Exposes port 8080
EXPOSE 8080 3306
# Install MySQL dependencies
RUN curl -L -o /tmp/mysql-connector-java-5.1.34.jar https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar && \
apt-get update && \
apt-get install -y /tmp/mysql-connector-java-5.1.34.jar libpq-dev && \
rm -rf /var/lib/apt/lists/*
However, on application deploy, I'm getting the following error:
t update && apt-get install -y /tmp/mysql-connector-java-5.1.34.jar libpq-dev && rm -rf /var/lib/apt/lists/*] returned a non-zero code: 100"
And obviously, my library is not installed. How can I install the MySQL Connector/J library with a Dockerfile?
apt-get install -y /tmp/mysql-connector-java-5.1.34.jar
This is not how apt-get works. It installs debian packages.
There is a package called libmysql-java that may be what you want.
You might also try something like
RUN curl -L -o /mysql-connector-java-5.1.34.jar https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar
ENV CLASSPATH=/mysql-connector-java-5.1.34.jar:${CLASSPATH}
Related
We have a Java Spring Boot application that runs in a Docker container. It is based on openjdk:13-jdk-alpine. We deploy it to Linux machines, but we are also able to run it locally on Windows machines, as well as on an Intel-based iMac.
We have found, though, that it cannot run properly on an ARM-based MacBook Pro. The exceptions we get are basic Java errors like "Can't find symbol Java.class[]," and other things that look like the JVM is off.
Is there a way to build a Docker image that will work on all these platforms, including the M1 MacBook Pro?
I have a lot of problems with Java containers too on my M1 macbook. For your problem, maybe you need to create your own docker image:
Dockerfile
FROM --platform=linux/arm64/v8 ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
EXPOSE 8080
RUN apt update \
&& apt upgrade -y \
&& apt install -y openjdk-13-jre git \
&& apt clean
RUN mkdir -pv /app && cd /app && \
git clone https://github.com/spring-guides/gs-spring-boot.git && \
cd /app/gs-spring-boot/initial && ./gradlew build
WORKDIR /app/gs-spring-boot/initial
ENTRYPOINT [ "./gradlew", "bootRun" ]
Build image
docker build -t test .
Run container
docker run --rm -p 8080:8080 test
Go to http://localhost:8080/ on your browser and your Spring-Boot application is running without Rosetta 2.
Disclaimer: I'm not a Java developer and my Dockerfile is for Proof of Concept purpose.
Remember that your Docker image is builded to ARM64 architecture. If you wanna run this container on a Intel/AMD processor, you have to change FROM --platform=linux/amd64 ubuntu:20.04 on your Dockerfile.
I made it work with the following image.
I pulled the image with
docker pull bellsoft/liberica-openjdk-alpine-musl:17
My Dockerfile:
FROM bellsoft/liberica-openjdk-alpine-musl:17
ADD build/libs/app-0.0.1-SNAPSHOT-plain.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
Now the docker build command worked
Build your images with multiarch support to get rid of all possible architecture failures in the future. To do this cleanly, avoid using anything related to the platform in your Dockerfile, just old-school Dockerfiles are ok.
If you are using github and github-actions, you may check this to build your images and push them into your image repository. This can be also used for building images which work on RaspberryPi like SBCs.
it's because image is not supported for m1 yet, you can build it for cross platform and run it
docker build --platform=linux/arm64 -t image:latest .
I cant find anything related to my question
I tried below docker file
RUN apt-get update && apt-get install -y \
software-properties-common
RUN apt-get update && \
apt-cache search openjdk && \
apt-get install openjdk-8-jdk && \
apt-get clean;
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f;
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
#tabula.errors.JavaNotFoundError: `java` command is not found from this Python
#process.Please ensure Java is installed and PATH is set for `java`
when i use import tabula im getting tabula.errors.JavaNotFoundError. can someone please help what to do to get rid of this error in docker ?
UPDATE:
Im using flask and mongodb. in flask there is a code responsible to read pdf files which is tabula and it needs Java as it says in its error. for other python package i installed with pipfile and pipfile.lock
RUN pip install pipenv
COPY Pipfile . #<---- contains tabula package
COPY Pipfile.lock . #<---- contains tabula package
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
##But i have no idea how to install java for tabula dependecy.
**************** FINAL UPDATE *****************
I replaced tabula with pdfplumber. now working good, thanks for all who tried to help me.
Generally one should refrain from using a container image with more than one main process, such as python and java, and I would personally advise finding a replacement to tabula-py that doesn't require a java enviroment for that is the best practice when using containers as specified here as so:
It is generally recommended that you separate areas of concern by using one service per container.
With that in mind, because I don't know if you can do those things I'm gonna provide an alternative as well.
this docker image packs multiple runnable environments into one such as java and python, and its dockerfile is listed here.
Because it encompasses more environments than you need you can slim it down to your needs.
there is also this project though it wasn't updated for awhile or this article describing a consise homebrewed python and java dockerfile
In case anyone is trying to achieve that and doesn't want to switch to another library, here is a way of making it work with Tabula.
By the way, here I'm using Tabula in jupyter notebook... but you just have to change the image from Jupyter to python to achieve what you want with Flask.
Your docker-compose will be like this:
jupyter:
container_name: jupyter_lab
build: .
ports:
- "8888:8888"
environment:
- JUPYTER_ENABLE_LAB=yes
volumes:
- ./work:/home/jovyan/work
This is your Dockerfile:
# Image base-notebook
FROM jupyter/minimal-notebook #getting the basic one.
# Change to root user to install java 8
USER root
# Install java 8
RUN apt-get update \
&& echo "Updated apt-get" \
&& apt-get install -y openjdk-8-jre \
&& echo "Installed openjdk 8"
# Install requirements
COPY requirements.txt ./
RUN pip3 install -r requirements.txt
RUN rm -rf requirements.txt
# Change to "$NB_USER" command so the image runs as a non root user by default
USER $NB_UID
Your requirements.txt
tabula.py
Create the folder "work" (that is the folder that is going to be synced with the container).
Now open the terminal and type docker-compose up --build
This command will build and start your container. With these steps, you should be ready to go.
Test with this line of code in the notebook:
from tabula import read_pdf
pdf = read_pdf("path_to_your_pdf.pdf", pages='all')
I am adding Apache Tika for extracting text out of documents and images (with TikaOcr) to an already existing service in the Azure Functions based on top of AppService. Now, Apache Tika requires tesseract to be installed in the machine locally. To overcome that, I used apt-get to set up (by ssh-ing) into the server but (from what I understand) the setup is performed on the base AppService layer. As a result, invocation of concurrent OCR commands really slow down my functions. Since there are no official binaries of Tesseract, I was wondering if any of the following is possible:
Bundle Tesseract with my Functions app
Build a docker image with Tesseract.
Build a multi-container docker app with a tesseract runtime image (tesseract-shadow/tesseract-ocr-re)
I have tried to build docker image (following instructions from here) with tesseract with the following dockerfile but Apache Tika fails to perform OCR with this.
ARG JAVA_VERSION=11
# This image additionally contains function core tools – useful when using custom extensions
#FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-core-tools AS installer-env
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-build AS installer-env
RUN apt-get update && apt-get install -y tesseract-ocr
COPY . /src/functions-tika-extraction
RUN cd /src/functions-tika-extraction && \
mkdir -p /home/site/wwwroot && \
mvn clean package && \
cd ./target/azure-functions/ && \
cd $(ls -d */|head -n 1) && \
cp -a . /home/site/wwwroot
# This image is ssh enabled
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-appservice
# This image isn't ssh enabled
#FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
I'm fairly new to Docker and Azure Platform so I may be missing something here, but how can I get my Azure Functions to work with Tesseract using Docker or any other method?
After reading through the docker docs and getting to know some basics about docker, I could finally figure out that tesseract was in fact installed, below Azure AppService layer which somehow does not allow a container to access it. Tesseract can be made available to Azure Functions if installed in the uppermost layer by including it in the bottom of the Dockerfile as follows:
ARG JAVA_VERSION=11
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-build AS installer-env
# remove this line
# RUN apt-get update && apt-get install -y tesseract-ocr
COPY . /src/functions-tika-extraction
RUN cd /src/functions-tika-extraction && \
mkdir -p /home/site/wwwroot && \
mvn clean package && \
cd ./target/azure-functions/ && \
cd $(ls -d */|head -n 1) && \
cp -a . /home/site/wwwroot
# This image is ssh enabled
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-appservice
# add the line here
RUN apt-get update && apt-get install -y tesseract-ocr
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
While it does satisfy my requirement of bundling tesseract-ocr with Azure Functions Java application, the invocation is still very slow unfortunately.
I want to run this kurento example: https://doc-kurento.readthedocs.io/en/stable/tutorials/java/tutorial-one2one.html
But I have some issues with application server when I building it on docker.
When I run kms docker - it run's successfully. I setted port of kurento-media-server as 8889:8888 and IP in docker container when I checked was 172.17.0.2. Also, I setted port of web app as 8081:8080.
When i tried to open a web-page - it was not responded.
My url was: https://192.168.0.2:8443, where 192.168.0.2 is IP of my server where I run docker. Also I tried to connect to docker container IP directly with https://172.17.0.3:8443.
Here's my app dockerfile.
FROM ubuntu:16.04
MAINTAINER USER1 "USER1#infinte.com"
RUN apt-get update
RUN apt-get install git -y
RUN apt-get install curl -y
RUN apt install apt-utils -y
RUN apt install maven -y
RUN apt install openjdk-8-jdk openjdk-8-jre -y
RUN apt-get install software-properties-common -y
RUN git clone https://github.com/Kurento/kurento-tutorial-java.git
WORKDIR kurento-tutorial-java/kurento-one2one-call-advanced/
EXPOSE 8080
ENTRYPOINT mvn -U clean spring-boot:run -Dkms.url=ws://172.17.0.2:8888/kurento
Here's my kms run command:
docker run -t --name kms -p 8889:8888 kurento/kurento-media-server
Here's my app server run command:
docker run -d --name apps -p 8081:8080 --link kms apps
What mistakes I have made here? May'be I need to change IP in ENTRYPOINT?
I spent many weeks to find out the reason why it's not working.
To make everything work, I needed to add --network=host line in docker command.
Correct docker command is
docker run --network=host -t --name apps -p 8081:8080 apps
I am developing an application using SpringBoot and Java with Docker.
I want to install Netcat in my application so that I can check if a specific container is up before my spring application starts.
I have tried
RUN apt-get update && apt-get -y install netcat && apt-get clean
But it says apt-get is not found.
I am not sure how can I install any package manager in my java based application.
Or is there any other I can get net-cat installed.
Below is my Dockerfile
FROM openjdk:8
RUN apt-get update && apt-get -y install netcat && apt-get clean
ADD target/student.jar student.jar
EXPOSE 2018
ENTRYPOINT ["java","-jar","student.jar"]
apt-get is package manager for Debian-based Linux distros (including Ubuntu and others).
Try apk add instead.
Also, if you are using package managers in your Dockerfile, it is considered a good practice to explicitly specify Linux distro. In your case you can use openjdk:8-jdk-stretch variant or any other, where distro is specified.
I can get a successful docker build with this Dockerfile
FROM openjdk:8
RUN apt-get update && apt-get -y install netcat && apt-get clean
ENTRYPOINT ["/bin/bash"]
and apt-get works just fine. As far as I can tell openjdk:8 is Ubuntu (or at least Debian based). Even if I run
docker build . -t stackexample
docker run -it stackexample
and get inside the container, running netcat opens the netcat cmd.