DockerFile实战

DockerFile实战

构建简单的centos镜像

  • 官网docker hub:https://hub.docker.com/_/centos

  • 1、编写mydockerfile-centos 构建centos镜像

    FROM centos
    MAINTAINER faker55<923737581@qq.com>
    
    ENV MYPATH /usr/local
    WORKDIR  $MYPATH
    
    RUN yum -y install vim
    RUN yum -y install net-tools
    
    
    EXPOSE 80
    
    CMD echo $MYPATH
    CMD echo "---end---"
    CMD /bin/bash
    
  • 2、构建

    docker build -f mydockerfile-centos -t mycentos:0.1   .
    

构建tomcat镜像

1、准备镜像文件 tomcat压缩包和jdk压缩包

2、编写DockerFile文件

FROM centos
MAINTAINER faker55<923737581@qq.com>

COPY readme.txt  /usr/local/readme.txt

ADD jdk-8u201-linux-x64.tar.gz  /usr/local
ADD apache-tomcat-8.5.57.tar.gz  /usr/local

RUN yum -y install vim
RUN yum -y install net-tools

ENV MYPATH /usr/local
WORKDIR $MYPATH

ENV JAVA_HOME /usr/local/jdk1.8.0_201
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.57
ENV CATALINA_BASH /usr/local/apache-tomcat-8.5.57
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin

EXPOSE 8080

CMD /usr/local/apache-tomcat-8.5.57/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.57/logs/catalina.out

2、执行构建命令

 docker build -f mydockerfile-tomcat  -t diytomcat  .

3、查看镜像

[root@iZwz95n2hxcdh4x6vicjmgZ dockertomcat]# docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
diytomcat             latest              d8bd141df5bc        17 minutes ago      706MB

4、测试

[root@iZwz95n2hxcdh4x6vicjmgZ dockertomcat]# docker run -d -p 9090:8080 --name diytomcat01 -v /root/noob/build/tomcat/test:/usr/local/apache-tomcat-8.5.57/webapps/test  -v /root/noob/build/tomcat/tomcatlogs/:/usr/local/apache-tomcat-8.5.57/logs  diytomcat



# /root/noob/build/tomcat/test  项目就可以直接部署到宿主机的这个目录,容器数据卷会同步到dokcer容器中

5、查看容器运行状态

[root@iZwz95n2hxcdh4x6vicjmgZ dockertomcat]# docker ps | grep diytomcat
c659f31aaabc        diytomcat             "/bin/sh -c '/usr/lo…"   52 seconds ago      Up 52 seconds       0.0.0.0:9090->8080/tcp   diytomcat01

6、进入容器

[root@iZwz95n2hxcdh4x6vicjmgZ dockertomcat]# docker exec -it c659f31aaabc /bin/bash
[root@c659f31aaabc local]#

7、访问

curl localhost:9090
输出省略了,没问题

posted @ 2020-09-04 00:00  Noob52037  阅读(190)  评论(0编辑  收藏  举报