Docker安装tomcat和部署项目
随着微服务的流行,Docker越来越流行,正如它的理念”Build, Ship, and Run Any App, Anywhere”一样,Docker提供的容器隔离技术使得开发人员不用再去理清server里的各种环境配置,轻松把应用运行起来。我们只需把运行环境的配置和应用封装在Docker的镜像(image),然后使用Docker运行这个镜像即可。Docker可以说是给所有开发人员的一个福利包,学习和使用Docker是所有开发人员的标配技能。
安装Docker
yum install docker
本文使用的系统是centos7,ubuntu使用以下命令
sudo apt-get update
sudo apt-get install docker-engine
如果报了以下错误,是因为yum被其它进程使用了
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 12 M RSS (924 MB VSZ)
Started: Mon Jan 2 17:22:13 2017 - 1 day(s) 1:06:13 ago
State : Sleeping, pid: 16208
查看正在yum使用的进程
ps -ef|grep yum
kill掉它即可
kill -9 16208
安装完成,查看安装是否成功
docker info #查看docker的情况
docker --version #查看docker的版本
启动Docker服务
service docker start
启动Docker的hello-world
从Docker Hub下载一个hello-world镜像
docker pull hello-world
运行hello-world镜像
docker run hello-word
输出以下信息
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.
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容器
tomcat运行环境
1、搜索Docker Hub里的tomcat镜像
docker search tomcat
- 部分搜索结果如下
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementa... 1132 [OK]
dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba... 29 [OK]
cloudesire/tomcat Tomcat server, 6/7/8 12 [OK]
davidcaste/alpine-tomcat Apache Tomcat 7/8 using Oracle Java 7/8 wi... 11 [OK]
andreptb/tomcat Debian Jessie based image with Apache Tomc... 6 [OK]
可以看到,星数最高的是官方的tomcat,有关官方tomcat的镜像可以访问
https://hub.docker.com/r/library/tomcat/
上面 “7.0.73-jre7, 7.0-jre7, 7-jre7, 7.0.73, 7.0, 7”等等 是这个tomcat库支持的tag(标签),这里我们选用的是 “7” 这个标签
2、拉取Docker Hub里的镜像
docker pull tomcat:7
3、拉取完成后查看本地的镜像
docker images #所有镜像
docker image tomcat:7 #查看REPOSITORY为tomcat:7的镜像
4、运行tomcat镜像
docker run tomcat:7
可以访问 http://ip:8080 确认容器的tomcat已启动成功
- 使用以下命令来查看正在运行的容器
docker ps
- 若端口被占用,可以指定容器和主机的映射端口
docker run -p 8081:8080 tomcat:7
- 启动后,访问地址是http://ip:8081
5、运行我们的web应用
假设我们应用是www,目录位置在/app/deploy/www
docker run --privileged=true -v /app/deploy/www:/usr/local/tomcat/webapps/www -p 8081:8080 tomcat:7
-v /app/deploy/www:/usr/local/tomcat/webapps/www 是把/app/deploy/www的目录挂载至容器的/usr/local/tomcat/webapps/www。
–privileged=true是授予docker挂载的权限
至此,已成功把web应用部署在Docker容器运行
常用命令
# 查看所有镜像
docker images
# 正在运行容器
docker ps
# 查看docker容器
docker ps -a
# 启动tomcat:7镜像
docker run -p 8080:8080 tomcat:7
# 以后台守护进程的方式启动
docker run -d tomcat:7
# 停止一个容器
docker stop b840db1d182b
# 进入一个容器
docker attach d48b21a7e439
# 进入正在运行容器并以命令行交互
docker exec -it e9410ee182bd /bin/sh
# 以交互的方式运行
docker run -i -t -p 8081:8080 tomcat:7 /bin/bash
Docker安装tomcat和部署项目的更多相关文章
- docker安装Tomcat软件,部署项目
1 搜索tomcat镜像 $ sudo docker search tomcat NAME DESCRIPTION STARS OFFICIAL AUTOMATED tomcat Apache Tom ...
- docker安装tomcat并部署web项目
docker安装tomcat就不说了,网上一大把 启动tomcat: docker run --name tomcat -p 8080:8080 -v $PWD/test:/usr/local/tom ...
- docker安装Tomcat并部署war项目
转载:https://blog.csdn.net/javahighness/article/details/82859596 1进入容器 docker exec -it mytomcat bash 以 ...
- linux下安装tomcat,部署项目
一.先检查是否安装jdk java -version 查看版本信息,如果显示 那基本就是安装了. root@iZ2ze2hksqphzp0eh7dskoZ:/opt# java -version -b ...
- docker安装tomcat&部署javaweb程序
一.docker定制简单的java-web应用镜像 网址: 1.jdk下载网址:https://www.oracle.com/technetwork/java/javase/downloads/jdk ...
- CentOS安装tomcat并且部署Java Web项目具有一定的参考价值
本篇文章主要介绍了CentOS安装tomcat并且部署Java Web项目,具有一定的参考价值,有需要的可以了解一下.(http://m.8682222.com) 1.准备工作 b.因为tomcat的 ...
- Java Web开发: Tomcat中部署项目的三种方法
web开发,在tomcat中部署项目的方法: 可以参考http://m.blog.csdn.net/blog/u012516903/15741727 定义$CATALINA_HOME指的是Tomcat ...
- eclipse maven项目中使用tomcat插件部署项目
maven的tomcat插件部署web项目,我简单认为分两种,一种是部署到内置tomcat,另一种是部署到安装的tomcat. 第一种部署,默认是部署在内置tomcat的8080端口,如果不需要改端口 ...
- tomcat下部署项目的流程和遇到的问题笔记
简单部署流程: 1,解析域名关联到服务器ip 2,配置服务器jre运行环境 3,安装tomcat 4,项目打war包,放入tomcat根目录下webapps(tomcat默认加载的项目目录)目录下 5 ...
随机推荐
- kubernetes进阶(03)kubernetes的namespace
服务发现与负载均衡Kubernetes在设计之初就充分考虑了针对容器的服务发现与负载均衡机制,提供了Service资源,并通过kube-proxy配合cloud provider来适应不同的应用场景. ...
- Angular 学习笔记 (路由外传 - RouteReuseStrategy)
refer : https://github.com/angular/angular/issues/10929 https://stackoverflow.com/questions/41280471 ...
- 谈谈自己的理解:python中闭包,闭包的实质
闭包这个概念好难理解,身边朋友们好多都稀里糊涂的,稀里糊涂的林老冷希望写下这篇文章能够对稀里糊涂的伙伴们有一些帮助~ 请大家跟我理解一下,如果在一个函数的内部定义了另一个函数,外部的我们叫他外函数,内 ...
- AFNetWorking常用方法
NSURLConnection,主要对NSURLConnection进行了进一步的封装,包含以下核心的类: AFURLConnectionOperation AFHTTPRequestOperatio ...
- Codeforces Round #436 (Div. 2) D. Make a Permutation!
http://codeforces.com/contest/864/problem/D 题意: 给出n和n个数(ai <= n),要求改变其中某些数,使得这n个数为1到n的一个排列,首先保证修改 ...
- Python的字典和JSON
Python的字典和JSON在表现形式上非常相似 #这是Python中的一个字典 dic = { 'str': 'this is a string', 'list': [1, 2, 'a', 'b'] ...
- 找出一个文件夹下后缀名为.jpg的文件
import os list1=os.lisdir('E//') #方法一列表推导式 list2=[i for i in list1 if i.endswith('.jpg')] #方法二for循环 ...
- [C#].Net Core 获取 HttpContext.Current 以及 AsyncLocal 与 ThreadLocal
在 DotNetCore 当中不再像 MVC5 那样可以通过 HttpContext.Current 来获取到当前请求的上下文. 不过微软提供了一个 IHttpContextAccessor 来让我们 ...
- [LeetCode] Max Chunks To Make Sorted II 可排序的最大块数之二
This question is the same as "Max Chunks to Make Sorted" except the integers of the given ...
- [LeetCode] Valid Triangle Number 合法的三角形个数
Given an array consists of non-negative integers, your task is to count the number of triplets chose ...