docker的使用

安装参考:http://www.runoob.com/docker/centos-docker-install.html


一:安装docker
[root@izbp1gs6pfki4czk1u4c8hz ~]# uname -r 
3.10.0-862.2.3.el7.x86_64
[root@izbp1gs6pfki4czk1u4c8hz ~]# yum -y install docker-io
...
[root@izbp1gs6pfki4czk1u4c8hz ~]# docker run hello-world


Hello from Docker!
This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.


To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/


For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

二:Docker 安装 Tomcat

方法一、建立Dockerfile文件,内容如下:


#基础镜像
FROM centos


#维护人员信息
MAINTAINER gao666 "[email protected]"


#设置工作目录,这个命令是用来切换工作目录的,相当于cd命令
WORKDIR /home


#安装JDK


#创建JDK目录,等一下的JDK安装到这个目录


RUN mkdir JDK


#源文件的路径需要是Dockerfile文件所在目录,也可以使用wget、curl、apt-get等命令在线下载
COPY jdk-8u112-linux-x64.tar.gz /home/


#解压复制到镜像中的jdk压缩包,完成后删除,RUN命令可以使用 && 将两条命令放到一起。
RUN tar zxf /home/jdk-8u112-linux-x64.tar.gz -C /home/JDK && rm -rf /home/jdk-8u112-linux-x64.tar.gz


#设置环境变量
ENV JAVA_HOME /home/JDK/jdk1.8.0_112
ENV PATH $PATH:$JAVA_HOME/bin


#安装tomcat,同JDK
RUN mkdir Tomcat 
COPY apache-tomcat-8.0.39.tar.gz /home/
RUN tar zxf /home/apache-tomcat-8.0.39.tar.gz -C /home/Tomcat && rm -rf /home/apache-tomcat-8.0.39.tar.gz


#暴露tomcat的内部端口,如果没有修改tomcat的配置文件的话,默认是8080端口
EXPOSE 8080


#启动容器时,执行脚本文件启动Tomcat并持续输出日志,防止容器退出。
ENTRYPOINT /home/Tomcat/apache-tomcat-8.0.39/bin/startup.sh && tail -f /home/Tomcat/apache-tomcat-8.0.39/logs/catalina.out


------file end-----
docker build -t tomcat .   //通过Dockerfile创建一个镜像
docker images|grep tomcat  //查找本地镜像 或者 docker images -a


方法二、
docker search tomcat
docker pull tomcat


运行tomcat容器
docker run --name tomcat -p 8080:8080 -v $PWD/test:/usr/local/tomcat/webapps/test -d tomcat 




-----------------------------------------------

你可能感兴趣的:(linux)