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.docker.com/
FROM centos:7
# author<email>
MAINTAINER auth<[email protected]>
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)
-
在linux中安裝jdk的教程(若不需要在宿主機上安裝jdk,可以跳過)
-
Java官方檔案:https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html
-
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.
-
Unpack the archive file and install the JDK. ( tar zxvf jdk-8uversion-linux-x64.tar.gz )
tar zxvf jdk-8u281-linux-x64.tar.gz -
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.
-
2、撰寫DockerFile檔案:vim Dockerfile1
FROM centos:7
MAINTAINER auth<[email protected]>
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 .
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/264361.html
標籤:其他
上一篇:30分鐘入門Vim
