这是我的Dockerfile:
#Build java web app container image
FROM ubuntu
MAINTAINER wangyao
#Make java and tomcat install directory
RUN mkdir /usr/local/java
RUN mkdir /usr/local/tomcat
#Copy jre and tomcat into image
ADD jdk1.8.0_45.jdk /usr/local/java/
ADD apache-tomcat-7.0.62 /usr/local/tomcat/
ENV JAVA_HOME=/usr/local/java/Contents/Home
CMD cd /usr/local/tomcat;./bin/catalina.sh run
#Expose http port
EXPOSE 8080
然后我构建它并尝试启动它:
wangyaos-MBP-3:flexcloud wangyao$ ls
Dockerfile apache-tomcat-7.0.62 jdk1.8.0_45.jdk
wangyaos-MBP-3:flexcloud wangyao$ docker build -t flexcloud .
Sending build context to Docker daemon 355.6 MB
Sending build context to Docker daemon
........
Successfully built 1f824d246b39
wangyaos-MBP-3:flexcloud wangyao$ docker run -i -t flexcloud
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java/Contents/Home
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
/usr/local/java/Contents/Home/bin/java: 20: /usr/local/java/Contents/Home/bin/java: Syntax error: word unexpected (expecting ")")
wangyaos-MBP-3:flexcloud wangyao$
word unexpected (expecting ")")
是什么意思?
我使用$ ./bin/catalina.sh run
没有docker,我可以运行它,但我为什么不能在docker容器上运行它?
答案 0 :(得分:1)
如评论中所示,错误Syntax error: word unexpected (expecting ")")
是一个shell脚本错误,这意味着/usr/local/java/Contents/Home/bin/java
实际上不是java可执行文件。
根据@ KingOfSocket的评论,使用docker exec -it <container> bash
访问容器并执行/usr/local/java/Contents/Home/bin/java -version
向我们展示了实际情况。