Docker化的java应用

什么是docker

docker历史

 2010 dotCloud PAAS

    2013 docker开源

    2014.6 Docker1.0

Docker is the world's leading software containerization platform.

Docker公司开发,开源,托管在github

 

Docker思想

  集装箱

  标准化:运输方式、存储方式、API接口

  隔离

Docker解决了什么问题

  docker解决了运行环境不一致所带来的问题

     docker标准化,让快速扩展、弹性伸缩变得简单

Docker核心技术

 镜像 仓库 容器 

 Build:构建镜像

 Ship:运输镜像,从仓库和主机上运输

 Run:运行镜像,就是一个容器

 

Docker镜像

联合文件系统,分层的概念 实现的文件存储,每一层文件是只读的

 

Docker容器

容器的本质就是一个进程

最上面的一层是可写的文件系统,镜像每一层都是只读的。在写镜像文件的时候会把镜像文件拷到容器最上层,然后再对它进行修改。应用读文件的时候会从顶层开始查找,如果没有才会找下一层。

Docker仓库

中央服务器

  hub.docker.com

  c.163.com

Windows安装Docker

 在windows系统中Docker目前仅有win10专业版和企业版的安装包,win7/win8/win10家庭版需要通过docker toolbox来安装。

 下载地址:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/

 Linux 安装Docker

  Redhat & Centos

    系统要求:64-bit OS and version 3.10

    安装教程:https://www.imooc.com/article/16448

  Ubuntu

    系统要求:64-bit OS and version 3.10

    1.apt-get update

    2.apt-get install -y docker.io 系统自带

     curl -s https://get.docker.com|sh   最新版本
    3.docker version

    4.service docker start

Docker初体验

  第一个docker镜像

    docker pull [OPTIONS] NAME [:TAG]    ---拉取i镜像

      TAG版本的意思,不填默认最新版本 

    docker images [OPTIONS] [REPOSITORY[:TAG]]   ---查看本机镜像

      REPOSITORY:镜像名称

    操作

      docker pull hello-world

      docker images

  第一个docker容器

     docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]

      COMMAND:镜像运行起来要执行什么命令

      ARG...:命令运行所需参数

     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.

 

Docker运行Nginx

  实践前奏

    持久运行的容器

    前台挂起&后台运行

    进入容器内部

  网易镜像中心:https://c.163yun.com/hub#/home

    拉取镜像:docker pull hub.c.163.com/library/nginx:latest

    运行镜像:docker run hub.c.163.com/library/nginx  --前台运行

         docker run -d hub.c.163.com/library/nginx  --后台运行

         docker run --help  --查看参数

    进入容器内部:docker exec -it b22 bash

           docker exec -- help

           docker ps   ---产看当前主机运行的docker容器

  docker网络

     网络类型   namespace--network namespace

      Bridge   Host  None

    端口映射

 

映射命令

    docker run 

      -p, --publish list Publish a container's port(s) to the host
      -P, --publish-all Publish all exposed ports to random ports

    docker run -d -p 8080:80 hub.c.163.com/library/nginx

  windows 端口映射查询IP命令: docker-machine ip default

    docker run -d -P hub.c.163.com/library/nginx

第一个Java Web应用

  Dockerfile

  docker build

  Jpress:http://jpress.io

 

下载Jpress war包

下载tomcat镜像

docker pull hub.c.163.com/library/tomcat:latest

 

Dockerfile

docker build .

docker build -t jepress:latest .

docker run -d -p 8888:8080 jpress

docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=000000 -e MYSQL_DATABASE=jpress hub.c.163.com/library/mysql:latest

上传网易镜像仓库参考:https://www.163yun.com/help/documents/15587826830438400

posted @ 2020-07-13 17:50  110528844  阅读(193)  评论(0编辑  收藏  举报