在Docker中安装openjdk会删除基本的Linux命令 [英] Installing openjdk in docker removes basic linux commands
问题描述
我旨在制作一个包含qt-android和android-studio工具的docker映像.我喜欢dockerfile的基础这一个,并且我没有安装 software-properties-common
,而是安装了 build-essential
和 libgl1-mesa-dev
.Java库和这些库均已成功安装,但是随后,诸如 mkdir
, ls
, cd
之类的基本命令变得无法识别,从而使docker构建过程返回,代码为127(找不到命令).
I aim to make a docker image that contains qt-android and android-studio tool. I took like base for dockerfile this one, and, instead of installing software-properties-common
, I've put to install build-essential
and libgl1-mesa-dev
. Both Java and theses libraries were installed with success, but, then, basic commands like mkdir
, ls
, cd
turned to be unrecognizable, making docker build process return with code 127 (command not found).
为什么会这样?
推荐答案
我发现,如果不对映像进行更早的更改,我什至无法让您的Dockerfile显示问题.实际是您的问题所在的是:
I found that I couldn't even get your Dockerfile to display the issue without making some changes earlier in the image. The bit that was actually your problem though is:
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
ENV PATH JAVA_HOME/bin
ENV CLASSPATH JAVA_HOME/lib/tools.jar
ENV MANPATH JAVA_HOME/man
RUN export JAVA_HOME PATH CLASSPATH MANPATH
应成为:
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
ENV PATH $PATH:$JAVA_HOME/bin
ENV CLASSPATH $JAVA_HOME/lib/tools.jar
ENV MANPATH $JAVA_HOME/man
这是因为设置PATH时,您不应该删除它的当前内容(因此 $ PATH:
),而是要添加JAVA_HOME变量的值而不是文字字符串JAVA_HOME(因此 $ JAVA_HOME/bin
).
This is because when you set the PATH you shouldn't remove the current contents of it (hence $PATH:
) and you want to add the value of the JAVA_HOME variable rather than the literal string JAVA_HOME (hence $JAVA_HOME/bin
).
此外,您使用ENV设置的任何内容都无需导出,因为它可用于图像中的每个进程.
Also, anything you set with ENV you will not need to export as it will be available for every process in your image.
我还必须安装一些软件包以使add-apt-repository可用,但我不确定100%是否是因为ubuntu:latest指的是我系统上的其他映像(可能您应该考虑使用标记用于您希望使用的特定版本,例如 ubuntu:xenial
).
I also had to install some packages to make add-apt-repository available but I'm not 100% sure if this is because ubuntu:latest refers to a different image on my system (possibly you should consider using a tag for the specific version you wish to use like ubuntu:xenial
).
我还必须安装wget&我更正了许多您不打算使用 wget -O-
的地方(因为您显然想将文件写入磁盘).
I also had to install wget & I corrected a number of places where you were using wget -O -
where you didn't mean to (as you clearly wanted to write the files to disk).
我使用的完整Dockerfile&能够成功构建(我没有测试运行它,因为我不确定预期的行为并不会说您的语言)是:
The full Dockerfile which I used & was able to get to successfully build (I didn't test running it as I'm not sure on expected behaviour & don't speak your language) is:
# BASED ON : https://hub.docker.com/r/picoded/ubuntu-openjdk-8-jdk/~/dockerfile/
FROM ubuntu:latest
MAINTAINER Inacio Medeiros <inaciogmedeiros@gmail.com>
USER root
# Install the python script required for "add-apt-repository"
RUN apt-get update
RUN apt-get install build-essential libgl1-mesa-dev -y --force-yes
# Sets language to UTF8 : this works in pretty much all cases
ENV LANG pt_BR.UTF-8
RUN locale-gen $LANG
# Install add-apt-repository
RUN apt-get install software-properties-common python-software-properties wget -y --force-yes
# INSTALL JAVA
# ==============================================================
# Setup the openjdk 8 repo
RUN add-apt-repository ppa:openjdk-r/ppa
# Install java8
RUN apt-get update && apt-get install openjdk-8-jdk -y --force-yes
# Setup JAVA_HOME and other environment variables, this is useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
ENV PATH $PATH:$JAVA_HOME/bin
ENV CLASSPATH $JAVA_HOME/lib/tools.jar
ENV MANPATH $JAVA_HOME/man
# ==============================================================
# Install QT Android
# ==============================================================
RUN mkdir /var/tmp/qt-android \
&& cd /var/tmp/qt-android \
&& wget "http://download.qt.io/official_releases/qt/5.5/5.5.0/qt-opensource-linux-x64-android-5.5.0-2.run" \
&& chmod 777 qt-opensource-linux-x64-android-5.5.0-2.run
CMD /var/tmp/qt-android/qt-opensource-linux-x64-android-5.5.0-2.run
RUN cd /var/tmp/qt-android \
&& cd .. \
&& rm -rf /var/tmp/qt-android
# ==============================================================
# Install Ant
RUN apt-get install ant -y --force-yes
# Install SDK
RUN mkdir /opt/android-sdk \
&& cd /opt/android-sdk \
&& wget -O - "http://dl.google.com/android/android-sdk_r24.3.4-linux.tgz" \
| tar --strip-components=1 -zxf -
#Install NDK
RUN mkdir /var/tmp/ndk \
&& cd /var/tmp/ndk \
&& wget "http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin" \
&& chmod 777 android-ndk-r10e-linux-x86_64.bin
CMD /var/tmp/ndk/android-ndk-r10e-linux-x86_64.bin
RUN cd /var/tmp/ndk \
&& cd .. \
&& rm -rf ndk
# Run SDK Update
RUN cd /opt/android-sdk/tools \
&& chmod 777 android
CMD /opt/android-sdk/tools/android update sdk
# Update libraries
RUN apt-get update && apt-get upgrade -y --force-yes
# Install libraries
RUN apt-get install -y --force-yes libstdc++6 libgcc1 zlib1g libncurses5
RUN apt-get install -y --force-yes libsdl1.2debian
# Install Android studio
# Source: https://github.com/wolfitem/docker/blob/master/Dockerfiles/android-studio/Dockerfile
RUN apt-get install unzip -y --force-yes
RUN wget 'https://dl.google.com/dl/android/studio/ide-zips/2.1.0.9/android-studio-ide-143.2790544-linux.zip' -O /tmp/studio.zip && unzip -d /opt /tmp/studio.zip && rm /tmp/studio.zip
#clean up
RUN apt-get clean
RUN apt-get purge
USER developer
CMD /opt/android-studio/bin/studio.sh
我注意到的事情是,在很多地方您都可以执行类似 CMD/var/tmp/qt-android/qt-opensource-linux-x64-android-5.5.0-2的操作.在您想要运行
.我认为您可能已经误解了CMD的功能-它实际上并未运行该命令,而是对其进行了设置,因此当您使用/var/tmp/qt-android/qt-opensource-linux-x64-android-5.5.0-2.run
的地方运行 docker run
从映像运行容器时,它将是默认命令.
The thing which I did notice is there are a number of places where you do something like CMD /var/tmp/qt-android/qt-opensource-linux-x64-android-5.5.0-2.run
where it looks like you are wanting to run /var/tmp/qt-android/qt-opensource-linux-x64-android-5.5.0-2.run
. I think you have possibly misunderstood what CMD does - it doesn't actually run that command, it sets it up so that when you run a container from the image with docker run
that will be the default command.
如果我不得不重构Dockerfile,我会让它看起来更像下面的文件.但这当前无法建立,因为我将其更改为实际上称为上述内容.当前 qt-opensource-linux-x64-android-5.5.0-2.run
失败,因为它找不到要连接的显示器.
If I had to refactor the Dockerfile I would make it look more like the one below. But this currently fails to build because I changed it to actually call the things mentioned above. Currently qt-opensource-linux-x64-android-5.5.0-2.run
fails because it can't find a display to connect to.
FROM ubuntu:latest
MAINTAINER Inacio Medeiros <inaciogmedeiros@gmail.com>
# Install the python script required for "add-apt-repository"
RUN apt-get update \
&& apt-get install -y --force-yes \
build-essential \
libgl1-mesa-dev \
python-software-properties \
software-properties-common \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Sets language to UTF8 : this works in pretty much all cases
ENV LANG pt_BR.UTF-8
RUN locale-gen $LANG
# INSTALL JAVA
# ==============================================================
# Setup the openjdk 8 repo
RUN add-apt-repository ppa:openjdk-r/ppa
# Install java8
RUN apt-get update \
&& apt-get install -y --force-yes \
openjdk-8-jdk \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Setup JAVA_HOME and other environment variables, this is useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
ENV PATH $PATH:$JAVA_HOME/bin
ENV CLASSPATH $JAVA_HOME/lib/tools.jar
ENV MANPATH $JAVA_HOME/man
# ==============================================================
# Install QT Android
# ==============================================================
RUN mkdir -p /var/tmp/qt-android \
&& cd /var/tmp/qt-android \
&& wget "http://download.qt.io/official_releases/qt/5.5/5.5.0/qt-opensource-linux-x64-android-5.5.0-2.run" \
&& chmod 777 qt-opensource-linux-x64-android-5.5.0-2.run \
&& /var/tmp/qt-android/qt-opensource-linux-x64-android-5.5.0-2.run \
&& cd / \
&& rm -rf /var/tmp/qt-android
# ==============================================================
# Install Ant
RUN apt-get update \
&& apt-get install -y --force-yes \
ant \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install SDK
RUN mkdir -p /opt/android-sdk \
&& cd /opt/android-sdk \
&& wget -O - "http://dl.google.com/android/android-sdk_r24.3.4-linux.tgz" \
| tar --strip-components=1 -zxf -
#Install NDK
RUN mkdir /var/tmp/ndk \
&& cd /var/tmp/ndk \
&& wget "http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin" \
&& chmod 777 android-ndk-r10e-linux-x86_64.bin \
&& /var/tmp/ndk/android-ndk-r10e-linux-x86_64.bin \
&& cd / \
&& rm -rf /var/tmp/ndk
# Run SDK Update
RUN cd /opt/android-sdk/tools \
&& chmod 777 android \
&& /opt/android-sdk/tools/android update sdk
# Update libraries
RUN apt-get update \
&& apt-get upgrade -y --force-yes \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install libraries
RUN apt-get update \
&& apt-get install -y --force-yes \
libstdc++6 \
libgcc1 \
libsdl1.2debian \
zlib1g \
libncurses5 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install Android studio
# Source: https://github.com/wolfitem/docker/blob/master/Dockerfiles/android-studio/Dockerfile
RUN apt-get update \
&& apt-get install -y --force-yes \
unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN wget 'https://dl.google.com/dl/android/studio/ide-zips/2.1.0.9/android-studio-ide-143.2790544-linux.zip' -O /tmp/studio.zip \
&& unzip -d /opt /tmp/studio.zip \
&& rm /tmp/studio.zip
USER developer
CMD /opt/android-studio/bin/studio.sh
让我知道您是否还有其他问题,我会尽力回答.
Let me know if you have any further questions and I will do my best to answer them.
这篇关于在Docker中安装openjdk会删除基本的Linux命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!