NutzCN Logo
问答 Dockerfile rpm安装jdk设置环境变量 问题
发布于 1820天前 作者 Hamming 3458 次浏览 复制 上一个帖子 下一个帖子
标签:

Dockerfile 配置如下

#指定操作的镜像
FROM centos
# 维护者信息
MAINTAINER Tom Yule <brave.yhm@gmail.com>
#tomcat 版本
ENV TOMCAT_VERSION 9.0.29

# 安装基本工具
RUN yum -y upgrade && \
    yum -y update && \
    yum -y install wget unzip findutils

# jdk 安装
ADD jdk-8u231-linux-i586.rpm  /opt
RUN cd /usr/local \
    && yum -y install /opt/jdk-8u231-linux-i586.rpm \
    && yum install which -y 

ENV	JAVA_HOME=/usr/java/jdk1.8.0_231-i586
ENV	JRE_HOME=$JAVA_HOME/jre
ENV	CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
ENV	PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

#WORKDIR	/bin/sh

# Get Tomcat
RUN wget --quiet --no-cookies http://apache.rediris.es/tomcat/tomcat-9/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz -O /tmp/tomcat.tgz && \
tar xzvf /tmp/tomcat.tgz -C /opt && mv /opt/apache-tomcat-${TOMCAT_VERSION} /opt/tomcat

# Remove garbage
RUN rm /tmp/tomcat.tgz && rm -rf /opt/tomcat/webapps/examples && rm -rf /opt/tomcat/webapps/docs && rm -rf /opt/tomcat/webapps/ROOT

# Add admin/admin user
#ADD tomcat-users.xml /opt/tomcat/conf/

ENV CATALINA_HOME /opt/tomcat
ENV PATH $PATH:$CATALINA_HOME/bin

EXPOSE 8080
EXPOSE 8009
EXPOSE 4110
#VOLUME "/opt/tomcat/webapps"
WORKDIR /opt/tomcat

CMD ["catalina.sh", "run"]
#CMD /opt/tomcat/bin/sartup.sh && tail -f /opt/tomcat/logs/catalina.out

vim Dockerfile
构建镜像
docker build -t haiming/java8 .
运行
docker run -it haiming/java8 /bin/bash

进入镜像后
输入Java
提示如下
环境变量没有设置成功 这个为什么呢 求大神解答

bash: /usr/java/jdk1.8.0_231-i586/bin/java: No such file or directory
6 回复

i586?应该下载amd64的

感谢 现在可以了

#指定操作的镜像
FROM centos
# 维护者信息
MAINTAINER Tom Yule <brave.yhm@gmail.com>
#tomcat 版本
ENV TOMCAT_VERSION 9.0.29

# 安装基本工具
RUN yum -y upgrade && \
    yum -y update && \
    yum -y install wget unzip findutils

# jdk 安装
ADD jre-8u192-linux-x64.rpm  /opt
RUN cd /usr/local \
    && yum -y install /opt/jre-8u192-linux-x64.rpm \
    && yum install which -y

ENV	JAVA_HOME=/usr/java/jre1.8.0_192-amd64
#ENV	JRE_HOME=$JAVA_HOME/jre
#ENV	CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
#ENV	PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

#WORKDIR	/bin/sh

# Get Tomcat
RUN wget --quiet --no-cookies http://apache.rediris.es/tomcat/tomcat-9/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz -O /tmp/tomcat.tgz && \
tar xzvf /tmp/tomcat.tgz -C /opt && mv /opt/apache-tomcat-${TOMCAT_VERSION} /opt/tomcat

# Remove garbage
#RUN rm /tmp/tomcat.tgz && rm -rf /opt/tomcat/webapps/examples && rm -rf /opt/tomcat/webapps/docs && rm -rf /opt/tomcat/webapps/ROOT

# Add admin/admin user
#ADD tomcat-users.xml /opt/tomcat/conf/

ENV CATALINA_HOME /opt/tomcat
ENV PATH $PATH:$CATALINA_HOME/bin

EXPOSE 8080
EXPOSE 8009
EXPOSE 4110
#VOLUME "/opt/tomcat/webapps"
WORKDIR /opt/tomcat

CMD ["catalina.sh", "run"]
#CMD /opt/tomcat/bin/sartup.sh && tail -f /opt/tomcat/logs/catalina.out

安装MySQL又出问题了 命令

# installs from mysql public repo
RUN yum -y localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
RUN yum -y install mysql-community-server

RUN /etc/init.d/mysqld start &&\
mysql -e "grant all privileges on *.* to 'root'@'%' identified by 'ikmcy2O1904';" &&\
mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'ikmcy2O1904';"

EXPOSE 3306
CMD ["mysqld_safe"]

提示找不到 No match for argument: mysql-community-server

Step 16/21 : WORKDIR /opt
 ---> Using cache
 ---> f1475a916603
Step 17/21 : RUN yum -y localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
 ---> Running in 3dc649449ee5
Last metadata expiration check: 4:45:30 ago on Fri Nov 22 01:45:06 2019.
mysql80-community-release-el7-1.noarch.rpm      3.2 kB/s |  25 kB     00:07
Dependencies resolved.
================================================================================
 Package                        Arch        Version     Repository         Size
================================================================================
Installing:
 mysql80-community-release      noarch      el7-1       @commandline       25 k

Transaction Summary
================================================================================
Install  1 Package

Total size: 25 k
Installed size: 31 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : mysql80-community-release-el7-1.noarch                 1/1
  Verifying        : mysql80-community-release-el7-1.noarch                 1/1

Installed:
  mysql80-community-release-el7-1.noarch

Complete!
Removing intermediate container 3dc649449ee5
 ---> 6f4e543ae434
Step 18/21 : RUN yum -y install mysql-community-server
 ---> Running in 669693cf1eb2
MySQL Connectors Community                       14 kB/s |  59 kB     00:04
MySQL Tools Community                            33 kB/s | 343 kB     00:10
MySQL 8.0 Community Server                       12 kB/s | 973 kB     01:21
Last metadata expiration check: 0:00:01 ago on Fri Nov 22 06:31:05 2019.
No match for argument: mysql-community-server
Error: Unable to find a match
The command '/bin/sh -c yum -y install mysql-community-server' returned a non-zero code: 1

这个又是为什么呢 求大神指点

酱紫解决了

RUN yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm -y \
    && yum -y install mysql-server

docker 通过 Dockerfile 创建镜像 入门到放弃

#指定操作的镜像
FROM centos:7
# 维护者信息
MAINTAINER Tom Yule <brave.yhm@gmail.com>

# Set locales
ENV LANG=zh_CN.UTF-8
ENV LC_ALL=C
ENV LC_COLLATE=zh_CN.UTF-8

#tomcat 版本
ENV TOMCAT_VERSION 9.0.29

# 安装基本工具
RUN yum -y upgrade && \
    yum -y update && \
    yum -y install wget unzip findutils

# jdk 安装
ADD jre-8u192-linux-x64.rpm  /opt
RUN cd /usr/local \
    && yum -y install /opt/jre-8u192-linux-x64.rpm \
    && yum install which -y

ENV	JAVA_HOME=/usr/java/jre1.8.0_192-amd64
#ENV	JRE_HOME=$JAVA_HOME/jre
#ENV	CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
#ENV	PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

#WORKDIR	/bin/sh

# Get Tomcat
RUN wget --quiet --no-cookies http://apache.rediris.es/tomcat/tomcat-9/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz -O /tmp/tomcat.tgz && \
tar xzvf /tmp/tomcat.tgz -C /opt && mv /opt/apache-tomcat-${TOMCAT_VERSION} /opt/tomcat

# Remove garbage
#RUN rm /tmp/tomcat.tgz && rm -rf /opt/tomcat/webapps/examples && rm -rf /opt/tomcat/webapps/docs && rm -rf /opt/tomcat/webapps/ROOT

# Add admin/admin user
#ADD tomcat-users.xml /opt/tomcat/conf/

ENV CATALINA_HOME /opt/tomcat
ENV PATH $PATH:$CATALINA_HOME/bin

EXPOSE 8080
EXPOSE 8009
EXPOSE 4110
#VOLUME "/opt/tomcat/webapps"
WORKDIR /opt

RUN yum localinstall http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm -y \
    && yum install mysql-server -y \
    && systemctl enable mysqld.service

# 下载项目
RUN wget --quiet --no-cookies https://github.com/TomYule/NutzSite/archive/master.zip -O /opt/nutzsite.zip && \
     unzip /opt/nutzsite.zip && mv /opt/NutzSite-master /opt/tomcat/webapps/nutzsite
WORKDIR /opt/tomcat

CMD ["catalina.sh", "run"]
#CMD /opt/tomcat/bin/sartup.sh && tail -f /opt/tomcat/logs/catalina.out

#EXPOSE 3306
#CMD ["mysqld_safe"]

MySQL 安装完成了 就直接挂了
Docker的设计理念是在容器里面不运行后台服务,容器本身就是宿主机上的一个独立的主进程,也可以间接的理解为就是容器里运行服务的应用进程。一个容器的生命周期是围绕这个主进程存在的,所以正确的使用容器方法是将里面的服务运行在前台
https://blog.51cto.com/lizhenliang/1975466
啊啊啊啊啊啊
想创建一个镜像 可以任何人 下载镜像 运行 结果这么困难

原来是这个目的,你需要docker compose

添加回复
请先登陆
回到顶部