如何使用 docker-compose.yaml 在气流容器中安装 java [英] How to install java in an airflow container using docker-compose.yaml
问题描述
我正在使用这个 docker-compose.yaml 文件在 docker 容器上运行气流.
I am using this docker-compose.yaml file to run airflow on docker container.
https://airflow.apache.org/docs/apache-airflow/2.0.2/docker-compose.yaml
我需要在其中一个容器中安装 JRE.如何添加指令以将 java 添加到 docker-compose.yaml 文件?
I need to install JRE in one of the containers. How do I add instruction to add java to the docker-compose.yaml file?
推荐答案
尝试以下操作:
在您还有 docker-compose.yml 的目录中创建以下 Dockerfile:
Create the following Dockerfile in the directory where you also have the docker-compose.yml:
FROM apache/airflow:2.0.2
USER root
# Install OpenJDK-11
RUN apt update && \
apt-get install -y openjdk-11-jdk && \
apt-get install -y ant && \
apt-get clean;
# Set JAVA_HOME
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/
RUN export JAVA_HOME
USER airflow
WORKDIR /app
COPY requirements.txt /app
RUN pip install --trusted-host pypi.python.org -r requirements.txt
为了通过 apt 安装软件包,您必须切换到 root 用户.稍后,我们切换回用户气流.工作目录的规范和通过 requirements.txt 安装 python 包可能不适用,具体取决于您的情况.
In order to install packages via apt, you have to switch to root user. Later, we switch back to user airflow. The specification of the working directory and the installation of python packages through requirements.txt might not apply, depending on your case.
然后,在您的 docker-compose.yml 中,在 &airflow-common
之后添加 build: .
.
Then, in your docker-compose.yml, add build: .
after &airflow-common
.
最后,使用 docker-compose up -d --build
构建您的管道.
Finally, build your pipeline using docker-compose up -d --build
.
有关更多信息,请查看此处:https://airflow.apache.org/docs/docker-stack/build.html#building-the-image
For more information, look here: https://airflow.apache.org/docs/docker-stack/build.html#building-the-image
这篇关于如何使用 docker-compose.yaml 在气流容器中安装 java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!