cloudrun failing with find_vma failed - java

my dockerfile for cloud run is as below.
FROM alpine:3.10.5
USER root
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
RUN apk add --no-cache python3 \
&& python3 -m ensurepip \
&& pip3 install --upgrade pip setuptools wheel \
&& rm -r /usr/lib/python*/ensurepip && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi
WORKDIR /opt/bin
RUN pip install Flask 'gunicorn>=20.0.1,<21' sqlalchemy pg8000 logger
COPY <some jar files>.jar /opt/bin/
COPY *.py /opt/bin/
RUN rm -r /root/.cache
CMD exec gunicorn --bind :$PORT --workers 2 --threads 8 --worker-tmp-dir /dev/shm --timeout 30 http_test
when I run the docker image on cloudrun, i get the following error when I send a GET request to the URL given by Cloudrun:
020-05-04 13:22:14.551 ISTContainer Sandbox: Unsupported syscall membarrier(0x10,0x0,0x0,0x8,0x3e57651d89a0,0x3e57651d8a30). It is very likely that you can safely ignore this message and that this is not the cause of any error you might be troubleshooting. Please, refer to https://gvisor.dev/c/linux/amd64/membarrier for more information.
2020-05-04 13:22:14.603 ISTOpenJDK 64-Bit Server VM warning: Can't detect primordial thread stack location - find_vma failed
Have tried different alpine images, switched to gunicorn20.0.1 to avoid libc issues, no avail. Any suggestions, help would be much appreciated.

while deploying the docker image in cloud run change the Execution environment to the second generation
Second generation PREVIEW
File system access, full Linux compatibility, faster performance.
had the same issue and I have fixed it, Hope it helps.

Related

How to make multiple runtimes available inside docker? Like how Java and python altogether inside docker with required dependencies like asyncpg

I am working in a Java spring boot application, running as a docker container.
The main purose of this application was to execute python scripts.
So inside the docker container, I had to make available python environment. I added the python runtime with this code.
But seems this is very basic python verson and I can not make other important libraries available.
Like, I wanted to add 'asyncpg' library so that I can use connection pool.
But it is not letting me to add asyncpg library.
Below is the docker file.
Note: I have commented '#FROM python:3.6-alpine', if I make this open then java runtime will not be available which is 'FROM openjdk:8u191-jre-alpine3.8'
------- Docker file --------------
*FROM openjdk:8u191-jre-alpine3.8
#FROM python:3.6-alpine
## Install bash
RUN apk add --no-cache curl tar bash
ENV APP_HOME /opt/app
# Create directory structure
RUN mkdir -p ${APP_HOME}/logs
RUN mkdir -p ${APP_HOME}/config
RUN mkdir -p ${APP_HOME}/libs
RUN mkdir -p ${APP_HOME}/scripts
# Add supporting script
ADD start.sh ${APP_HOME}/start.sh
RUN chmod +x ${APP_HOME}/start.sh
ADD wait-for-it.sh ${APP_HOME}/wait-for-it.sh
RUN chmod +x ${APP_HOME}/wait-for-it.sh
ADD load-ext-packages.sh ${APP_HOME}/load-ext-packages.sh
RUN chmod +x ${APP_HOME}/load-ext-packages.sh
## Add Spring Boot runnable jar
ADD *.jar ${APP_HOME}/
WORKDIR ${APP_HOME}
VOLUME [ "${APP_HOME}/logs" ]
VOLUME [ "${APP_HOME}/config" ]
VOLUME [ "${APP_HOME}/libs" ]
VOLUME [ "${APP_HOME}/scripts" ]
# Install Python
RUN apk add build-base
RUN apk add --update gcc
RUN apk --update add gcc build-base freetype-dev libpng-dev openblas-dev
RUN apk add --no-cache python3 python3-dev libevent-dev && \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --upgrade pip setuptools && \
pip3 install wheel && \
pip3 install --no-cache-dir asyncpg && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache
CMD ["./start.sh"]*
I have got one solution .. that at the first line of the docker file, I will first decleare the 'FROM alpine:3.7', and then inside the docker file I will keep adding the required runtimes and the dependent libraries accordingly. This way we can add mutiple runtimes.
Below the working docker compose where I have commented out both the lines for openjdk and python runtime and added FROM alpine:3.7:
Also some trick to add asyncpg library to the python runtime. This way I can now add any dependencies.
I can now work on asyncpg.
-------- Docker file ----------------
*#FROM openjdk:8u191-jre-alpine3.8
#FROM python:3.6-alpine
FROM alpine:3.7
## Install bash
RUN apk add --no-cache curl tar bash
ENV APP_HOME /opt/app
# Create directory structure
RUN mkdir -p ${APP_HOME}/logs
RUN mkdir -p ${APP_HOME}/config
RUN mkdir -p ${APP_HOME}/libs
RUN mkdir -p ${APP_HOME}/scripts
# Add supporting script
ADD start.sh ${APP_HOME}/start.sh
RUN chmod +x ${APP_HOME}/start.sh
ADD wait-for-it.sh ${APP_HOME}/wait-for-it.sh
RUN chmod +x ${APP_HOME}/wait-for-it.sh
ADD load-ext-packages.sh ${APP_HOME}/load-ext-packages.sh
RUN chmod +x ${APP_HOME}/load-ext-packages.sh
## Add Spring Boot runnable jar
ADD *.jar ${APP_HOME}/
WORKDIR ${APP_HOME}
VOLUME [ "${APP_HOME}/logs" ]
VOLUME [ "${APP_HOME}/config" ]
VOLUME [ "${APP_HOME}/libs" ]
VOLUME [ "${APP_HOME}/scripts" ]
RUN apk add build-base --no-cache python3 python3-dev && \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --upgrade pip setuptools && \
pip3 install --no-cache-dir asyncpg && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
CMD ["./start.sh"]*

Dockerfile & installation -> Package 'openjdk-8-jre-headless' has no installation candidate

I'm trying to install openjdk-8-jre vie DockerFile, as I build the docker images for my composer. But I'm hitting this error message.
Error message:
Package openjdk-8-jre-headless is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'openjdk-8-jre-headless' has no installation candidate
Here is the part from Dockerfile:
# Install openjdk and java cacerts
RUN apt-get update && apt-get install -y openjdk-8-jre-headless ca-certificates-java
If I install java directly from the console, by using exact same command without RUN, no problem with the package. But as I try installing it from the Dockerfile, I hit the error. I have understood that Docker uses same repos as the machine where docker is running? Ubuntu is version 16.04.
Or how I check available installation packages on Dockerfile? java - v gives an error..
Seems like you are using FROM python:3.8 as base and as mentioned by #masseyb in the comment under your question it does not have openjdk-8jre-headless package.
This may help you.
FROM python:3.7-alpine as base
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
RUN apk add --no-cache python3 \
&& python3 -m ensurepip \
&& pip3 install --upgrade pip setuptools \
&& rm -r /usr/lib/python*/ensurepip && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache
RUN pip install --trusted-host pypi.python.org flask
This example Dockerfile can get you Java python and flask

Check if Onion URL is live

I am making an Android application in Java. There is an onion Url that I want to check is live or not. Basically, Onion Url is mapped to an IP-address, so is there any Java library or API that can assist in determining this check?
Any help in this regard will be appreciated.
Thanks.
You need to have a server on which the tor will work and already give from it either the desired status or the page that you need. For the site tor-sites.link we did the proxying of the tor through the tor launched into the container and the express.js server. You can see how it works at previewer. Schematically, it looks like this:
HTTP request
express.js server
request to tor
returning a response to the client
This way you can get data from the onino site.
Dockerfile:
FROM node:slim
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
RUN apt-get update && apt-get install gnupg wget -y && \
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
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 google-chrome-stable -y --no-install-recommends && \
apt-get install tor -y --no-install-recommends && \
apt-get install torsocks -y --no-install-recommends && \
apt-get install curl gnupg && \
rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/app
RUN mkdir src
RUN mkdir tmp
COPY ./src ./src
COPY ./package.json \
./ecosystem.config.js \
./tsconfig.json \
./
RUN npm i -g pm2 npm#9.2.0
RUN yarn && yarn build
RUN rm -rf src
#HEALTHCHECK --start-period=150s --interval=300s --retries=99999 --timeout=120s CMD curl --fail http://localhost:3000/healthcheck || kill 1
EXPOSE 3000
CMD ["pm2-runtime", "start", "ecosystem.config.js"]

Android Studio 3.0 RunTimeException

I've installed Android Studio 3.0 on VirtualBox, OS Lubuntu.
During making project, there is an exception:
Error:java.util.concurrent.ExecutionException: java.lang.RuntimeException: No server to serve request. Check logs for details.
Error:Execution failed for task ':app:mergeDebugResources'.
Error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: No server to serve request. Check logs for details.
I've tried oracle-jdk8 and OpenJdk. The same promlem.
Not quite sure what your compile issue is, but regardless once you get past that you will more than likely run into the issue of not being able to run the Android Studio emulator with VirtualBox. Assuming you want to run the emulator my point being you may be wasting time trying to fix your issue. See the following old post Android emulator and virtualbox cannot run at same time.
Best to run Android Studio on your host machine.
I've been able to find the root cause: The error message means that Gradle cannot connect to some worker processes. In my case, the process was for 'aapt2'. Running 'ldd aapt2' indicated that some shared libraries were missing (mainly GLIBC). Since I'm using Docker based on Alpine Linux, it comes with a reduced GLIBC (glibc-musl). The solution was to simply install glibc.
Here is the complete Dockerfile for reference, although the missing libraries might be different for your distribution.
FROM openjdk:8-alpine
LABEL maintainer="Barry Lagerweij" \
maintainer.email="b.lagerweij#carepay.co.ke" \
description="Android Builder"
COPY android-packages /tmp/android-packages
RUN apk add --no-cache wget unzip ca-certificates \
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub \
&& wget -q -O /tmp/glibc.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.26-r0/glibc-2.26-r0.apk \
&& wget -q -O /tmp/glibc-bin.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.26-r0/glibc-bin-2.26-r0.apk \
&& apk add --no-cache /tmp/glibc.apk /tmp/glibc-bin.apk \
&& wget -q -O /tmp/android-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip \
&& mkdir -p /tmp/android-sdk/licenses \
&& unzip /tmp/android-tools.zip -d /tmp/android-sdk \
&& rm /tmp/android-tools.zip \
&& echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > /tmp/android-sdk/licenses/android-sdk-license \
&& echo "84831b9409646a918e30573bab4c9c91346d8abd" > /tmp/android-sdk/licenses/android-sdk-preview-license \
&& echo "d975f751698a77b662f1254ddbeed3901e976f5a" > /tmp/android-sdk/licenses/intel-android-extra-license \
&& mkdir ~/.android; echo "count=0" >> ~/.android/repositories.cfg \
&& /tmp/android-sdk/tools/bin/sdkmanager --package_file=/tmp/android-packages \
&& apk del wget unzip ca-certificates \
&& rm -rf /tmp/android-sdk/extras /tmp/android-sdk/tools/lib/x86 /tmp/android-sdk/tools/lib/monitor-* /tmp/glibc.apk /tmp/glibc-bin.apk /etc/apk/keys/sgerrand.rsa.pub
RUN mkdir /tmp/project \
&& echo "sdk.dir=/tmp/android-sdk" > /tmp/project/local.properties
ENV ANDROID_HOME /tmp/android-sdk
WORKDIR /tmp/project
I suggest you run 'ldd build-tools/26.0.2/aapt2' to see which libraries are missing from the OS.
I had this problem on lubuntu-32 bit. easiest solution is to use lubuntu-64 bit.

Docker alpine + oracle java: cannot find java

I've been trying to create an alpine-based docker image with Oracle Java (rather than openjdk). I have been specifically asked to create our own image here.
This is the Dockerfile I've come up with:
FROM alpine:3.6
RUN apk add --no-cache curl wget
RUN mkdir /opt/ && \
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie"\
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz && \
tar xvf jdk-8u131-linux-x64.tar.gz -C /opt/ && \
rm jdk-8u131-linux-x64.tar.gz && \
ln -s /opt/jdk1.8.0_131 /opt/jdk
ENV JAVA_HOME /opt/jdk
ENV PATH $PATH:/opt/jdk/bin
RUN echo $JAVA_HOME && \
echo $PATH
RUN which java
RUN java -version
There are some unnecessary commands (like echoing the JAVA_HOME dir) which were added to help with debugging, but now I'm stuck: RUN which java returns /opt/jdk/bin/java as expected, but RUN java -version returns /bin/sh: java: not found.
I've tried a few things, including symlinking the executable(s) into /usr/bin, to no avail.
What am I missing?
EDIT:
Final output from docker is:
The command '/bin/sh -c java -version' returned a non-zero code: 127
Final edit:
Thanks to diginoise for putting me on to MUSL vs libc. I found adding the following to my Dockerfile allowed me to build a working image:
RUN apk --no-cache add ca-certificates && \
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \
apk add glibc-2.25-r0.apk
Found at: https://github.com/sgerrand/alpine-pkg-glibc
You cannot achieve what you want
Alpine Linux uses MUSL as a Standard C library.
Oracle's Java for linux depends on GNU Standard C library (gclib).
Here is a bit more detailed info and official stance from Oracle on the topic
the JDK source code has not yet been ported to Alpine Linux, or more specifically, the musl C library. That is, it turns out that the thing about Alpine Linux that sticks out/is different from a JDK source code perspective is the C library.
The solution
If you looking for small Java Docker images, use OpenJDK ones.
openjdk:11-jre-slim image is only 77MB.
If you insist, on your head be it...
There is theoretical way, but it is not as trivial as you think.
You can find many examples of Alpine images running with OracleJDK like here or see expert's answer to this question as well.
They add the missing Standard GNU C library.
Be warned however...
All of these solutions could be in breach of Oracle's license agreement stating that the license is non-transferable, and the distributable is non-modifiable.
In the Dockerfiles you will find however:
Cookie: oraclelicense=accept-securebackup-cookie"
and many entries similar to
rm -rf ${JAVA_HOME}/*src.zip
For further details about legality of prepackaged Oracle's JRE or JDK Docker images see this article.
In case anyone needs fresh version of JDK I maintain Alpine Oracle JDK images https://hub.docker.com/r/expert/docker-java-minimal
Sources
https://github.com/unoexperto/docker-java-minimal/
I found an answer that works finally. All is needed is just the GlibC; huge thanks to S. Gerrand, this is such a big help.
Here's how to get the old JDK 8 running in Alpine 1.13:
FROM alpine:3.13
RUN apk --no-progress --purge --no-cache upgrade \
&& apk --no-progress --purge --no-cache add --upgrade \
curl \
wget \
openssh \
&& apk --no-progress --purge --no-cache upgrade \
&& rm -vrf /var/cache/apk/* \
&& curl --version
# Install vanilla GLibC: https://github.com/sgerrand/alpine-pkg-glibc
RUN curl -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.32-r0/glibc-2.32-r0.apk \
&& apk add glibc-2.32-r0.apk
RUN wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" \
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz \
&& tar xvf jdk-8u131-linux-x64.tar.gz -C /opt \
&& rm jdk-8u131-linux-x64.tar.gz \
&& ln -s /opt/jdk1.8.0_131 /opt/jdk
ENV JAVA_HOME /opt/jdk
ENV PATH $PATH:/opt/jdk/bin
RUN echo $JAVA_HOME && \
echo $PATH
RUN which java
RUN java -version
ENTRYPOINT [ "java" ]
# To test run: docker run -t khalifahks/alpine-java -version
# docker export <container-id> | docker import - khalifahks/alpine-java:exported
# quick interative termnal: docker run -it --entrypoint=sh khalifahks/alpine-java sh

Categories

Resources