一、在Centos7宿主机上启用ip转发功能html
# Avoid WARNING: IPv4 forwarding is disabled. Networking will not work. echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf systemctl restart network
二、编写DockerFile文件:vim Dockerfilejava
# 查询centos镜像版本:https://hub.docker.com/ FROM centos:7 # author<email> MAINTAINER auth<auth@163.com> ENV MYPATH /usr/local WORKDIR $MYPATH RUN yum -y install vim RUN yum -y install net-tools # 暴露端口 EXPOSE 80 CMD echo $MYPATH CMD /bin/bash
三、构建mycentos镜像(不要忘记最后的.)linux
docker build -f Dockerfile -t mycentos:1.0 .
四、经过mycentos镜像生成容器,而且更改容器的yum源docker
# 建立并运行容器 docker run -it --name mycentos01 mycentos:1.0 # yum repo (163) mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo yum clean all && yum makecache # ping test ping www.baidu.com
一、下载JDK到宿主机工做目录(如jdk-8u281-linux-x64.tar.gz)shell
在linux中安装jdk的教程(若不须要在宿主机上安装jdk,能够跳过)vim
Java官方文档:https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.htmlcentos
Change directory to the location where you would like the JDK to be installed, then move the .tar.gz archive file to the current directory.bash
Unpack the archive file and install the JDK. ( tar zxvf jdk-8uversion-linux-x64.tar.gz )oracle
tar zxvf jdk-8u281-linux-x64.tar.gz
curl
The JDK files are installed in a directory called jdk1.8.0_version in the current directory.
jdk1.8.0_281
Delete the .tar.gz file if you want to save disk space.
二、编写DockerFile文件:vim Dockerfile1
FROM centos:7 MAINTAINER auth<auth@163.com> ENV MYPATH /usr/local WORKDIR $MYPATH RUN yum -y install vim RUN yum -y install net-tools # COPY:将宿主机中指定的文件复制到docker容器中指定的路径 ADD:复制(如果压缩文件会先解压) ADD jdk-8u281-linux-x64.tar.gz /usr/local ENV JAVA_HOME /usr/local/jdk1.8.0_281 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV PATH $PATH:$JAVA_HOME/bin EXPOSE 80 CMD echo $MYPATH CMD /bin/bash
三、构建 jdk+centos7 镜像(不要忘记最后的.)
docker build -f Dockerfile1 -t mycentos:2.0 .