Installing google chrome in dockerfile [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 days ago.
Improve this question
Im finding some issue to built my images with google chrome .
Im building my automation framework for testing UI/API/DB . so far im able to execute API and DB test but UI. im not able to install google chrome browser . what should i do to fix this issue ?

This Dockerfile will install google chrome:
FROM ubuntu:22.04
RUN apt update && apt install -y wget
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb
RUN apt install --fix-broken -y
But it is not means it will work immediately. There sore configuration needed to run it, for example mount .Xauthority from host.
For example:
docker run -it --security-opt seccomp=unconfined --privileged --security-opt apparmor:unconfined \
-e DISPLAY=unix$DISPLAY \
-e PULSE_SERVER=unix:$XDG_RUNTIME_DIR/pulse/native \
-v "$HOME/.Xauthority:/root/.Xauthority:rw" \
-v /run/dbus/:/run/dbus/:rw \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /etc/machine-id:/etc/machine-id:ro \
-v /dev/shm:/dev/shm \
-v $XDG_RUNTIME_DIR/pulse:/run/user/1000/pulse \
--device /dev/snd:/dev/snd \
--net=host \
google-chrome-image
Probably you do not need to mount all of them.

Related

Running Docker maven container [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I want to copy maven project from my dekstop to maven container and compile it in container
I run the command :
docker run -it --rm --name my-maven-project -v "/Users/ahay/Desktop/aviv" -w "/usr/share" maven:3.6.3-jdk-8 mvn clean install
And get the error :
But from -v flag diractory I have pom.xml :
The issue probably just comes from the fact the working directory (CLI option -w) you set did not match the path of your project (CLI option -v).
So I guess you could try the following:
docker run -it --rm --name my-maven-project \
-v "/Users/ahay/Desktop/aviv:/usr/src/app" \
-w "/usr/src/app" maven:3.6.3-jdk-8 mvn clean install
or equivalently:
cd /Users/ahay/Desktop/aviv
docker run -it --rm --name my-maven-project \
-v "$PWD:/usr/src/app" \
-w "/usr/src/app" maven:3.6.3-jdk-8 mvn clean install

How can I set up and run a very simple php-apache server in a docker container that's already using another image?

I'm tasked with creating a very simple, web browser accessible gui that can run a specific java file within a docker container. To do this I've chosen to set up a php-apache server that serves an index.php document with the gui. The Dockerfile looks like this:
FROM php:7.0-apache
COPY src /var/www/html
EXPOSE 80
This gets the gui (index.php is inside the src folder) I've written up and running no problem, but it cannot access and run the required java files (obviously, since this creates a separate container).
The Question:
How can I set up a php-apache server inside the existing Dockerfile (provided below) doing the same thing as the Dockerfile above? My aim is to run the java file using php scripts and display the result to the user.
FROM openjdk:8-jre-slim
WORKDIR /usr/src/app
COPY ["./build/libs/*.jar", "./fooBar.jar"]
ENV JAVA_OPTS=${FOO_JAVA_OPTS}
CMD ["/usr/bin/tail", "-f", "/dev/null"]
I have not written the java file myself, only being tasked with running specific commands using it.
As it is Debian based images. one way of doing it, install packages in the container and create the new images from that.
root#310c94d8d75f:/usr/src/app# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
2: root#310c94d8d75f:/usr/src/app# apt update
3- root#310c94d8d75f:/usr/src/app# apt install apache2
4- root#310c94d8d75f:/usr/src/app# apt install php
finally run : docker commit
after this, you will get a new image with the mentioned name.
Ref: https://docs.docker.com/engine/reference/commandline/commit/
2: you can add the same command in Dockerfile and rebuild.
FROM openjdk:8-jre-slim
WORKDIR /usr/src/app
COPY ["./build/libs/*.jar", "./fooBar.jar"]
ENV JAVA_OPTS=${FOO_JAVA_OPTS}
CMD ["/usr/bin/tail", "-f", "/dev/null"]
RUN apt update && apt install apache2 -y && apt install php -y
There appears to be no easy way of merging images like I initially hoped (You cannot have multiple FROM statements in your Dockerfile). What I eventually ended up doing was to manually merge the two images (openjdk and php) into something like this:
FROM php:7.0-apache
ENV LANG C.UTF-8
RUN { \
echo '#!/bin/sh'; \
echo 'set -e'; \
echo; \
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home
RUN ln -svT "/usr/lib/jvm/java-8-openjdk-$(dpkg --print-architecture)" /docker-java-home
ENV JAVA_HOME /docker-java-home/jre
ENV JAVA_VERSION 8u212
ENV JAVA_DEBIAN_VERSION 8u212-b01-1~deb9u1
RUN set -ex; \
if [ ! -d /usr/share/man/man1 ]; then \
mkdir -p /usr/share/man/man1; \
fi; \
apt-get update; \
apt-get install -y --no-install-recommends openjdk-8-jre-headless="$JAVA_DEBIAN_VERSION"; \
rm -rf /var/lib/apt/lists/*; \
[ "$(readlink -f "$JAVA_HOME")" = "$(docker-java-home)" ]; \
update-alternatives --get-selections | awk -v home="$(readlink -f "$JAVA_HOME")" 'index($3, home) == 1 { $2 = "manual"; print | "update-alternatives --set-selections" }'; \
update-alternatives --query java | grep -q 'Status: manual'
COPY ["./build/libs/*.jar", "./FooBar.jar"]
ENV JAVA_OPTS=${FOO_JAVA_OPTS}
COPY gui/src /var/www/html
EXPOSE 80
Both are Debian based images so the merging were relatively easy (I also removed much of the cluttering comments from the original image source) and since the openjdk image were simpler, I added it on top of the php image instead of the other way around.

Docker install Java 8 link 404 not found [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to install java 8 in my Ubuntu 16.4 using Docker file but I get the below error -
Connecting to download.oracle.com (download.oracle.com)|65.202.184.96|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-10-19 15:34:18 ERROR 404: Not Found.
Dockerfile
FROM ubuntu:16.04
ENV GOSU_VERSION 1.9
ENV SPARK_VERSION 2.0.2
ENV SPARK_HOME /usr/local/spark
ENV SPARK_USER aml
ENV GLIBC_APKVER 2.24-r0
ENV LANG=en_US.UTF-8
LABEL vendor=ActionML \
version_tags="[\"1.6\",\"1.6.3\"]"
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
RUN apt-get update && \
apt-get dist-upgrade -y
RUN \
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get update && \
apt-get install -y oracle-java8-installer && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/oracle-jdk8-installer
FYI- As of this morning, the Webupd8 Oracle-java8-installer is successfully downloading and installing in docker for me. The links in the PPA installer must have been updated. Yay!
As root, go to this folder: /etc/apt/sources.list.d
Locate this file: webupd8team-java.list and delete it.
Execute sudo apt-get update for the system to remove any reference to that update server.
Execute add-apt-repository ppa:webupd8team/java to add the correct ppa to your system.
Execute sudo apt-get update again and you should be able to install everything correctly.

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

Dockerfile to download Java 8 on Amazon Beanstalk Linux

Trying to create a Dockerfile that'll download and install Java 8 on Amazon Linux.
Currently, I have the following file. It's a Play 2.3.4 app:
FROM dockerfile/java
RUN \
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-java8-installer && \
rm -rf /var/lib/apt/lists/*
MAINTAINER BeanstalkTest
EXPOSE 80 443
ADD files /
WORKDIR /opt/docker
RUN ["chown", "-R", "daemon", "."]
USER daemon
RUN ["bin/playapp", "-Dconfig.file=conf/prod.conf"]
The app takes a long time to deploy then fails. Any ideas what I could be doing wrong?
For me it looks like problem with connection.
Are you sure that this code works without Docker inside target host?
Does it work in your machine?
Are you sure that echo command is doing what you really want ? I mean installing java 8.
Ok so I will post my ideas:
Set up proxies: HTTP_PROXY, http_proxy, HTTPS_PROXY, https_proxy, http-proxy, https-proxy - yes that many proxies because different packages use different names of proxy.
Add proxy to etc/apt/apt.conf to Acquire::http::Proxy "http://proxy-abc.com:888/";
Add proxy to docker:
Inside etc/default/docker:
export http_proxy=http://proxy-abc.com:888/
export https_proxy=https://proxy-abc.com:888/
DOCKER_OPTS="-H tcp://127.0.0.1:4243 -H unix://var/run/docker.sock -g /docker"
Look at docker container logs: sudo cat log/var/lib/docker/containers/12eaca16d3cdc628304263b21d27614e5a0c44f09c2072470b09a1bb3def5559/12eaca16d3cdc628304263b21d27614e5a0c44f09c2072470b09a1bb3def5559-json.log
Does your target host has newest kernel ? In older kernels docker had problems with network communication
Does your target host had newest docker installed?
EDIT
Why wouldn't use prebuild images? FROM dockerfile/java:oracle-java8

Categories

Resources