DockerFile案例
案例1:自定义镜像mycentos
1、在Centos7宿主机上启用ip转发功能
# Avoid WARNING: IPv4 forwarding is disabled. Networking will not work.
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
systemctl restart network
2、编写DockerFile文件:vim Dockerfile
# 查询centos镜像版本:https://hub./
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
3、构建mycentos镜像(不要忘记最后的.)
docker build -f Dockerfile -t mycentos:1.0 .
4、通过mycentos镜像生成容器,并且更改容器的yum源
# 创建并运行容器
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
案例2:带有JDK的Centos7镜像
1、下载JDK到宿主机工作目录(如jdk-8u281-linux-x64.tar.gz)
2、编写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
3、构建 jdk+centos7 镜像(不要忘记最后的.)
docker build -f Dockerfile1 -t mycentos:2.0 .
|