CentOS7下Docker中构建可以自动发布到项目的Tomcat容器
步骤
- 下载镜像
- 搜索相应的镜像文件:docker search 'tomcat' 如下
- 下载镜像:docker pull tomcat:7,如下图
PS:后面的数字代表tomcat的版本,可以自己选择。如:tomcat:7;tomcat:8;tomcat:9
- 查看已经下载的tomcat镜像:docker images | grep "tomcat"
- 下载镜像:docker pull tomcat:7,如下图
- 制作新镜像
- 原因:项目进行远程自动发布需要修改tomcat的配置文件,文件修改后一定要重新构建一个新的镜像,通过这个镜像创建容器运行。
- 修改方法
- 方法一:通过镜像创造出tomcat容器,修改容器中文件,然后通过容器重新构建一个新的tomcat镜像,最后通过这个新镜像运行容器。自己亲测:通过此步骤创建容器后,修改的文件不生效!!!以后会找原因。。。。
- 方法二:通过Dockerfile创造镜像,步骤如下
- 创建一个目录用来存放所需文件
- 创建目录:mkdir /home/jingguoliang/docker/tomcat_dockerfile(路径为栗子)
- 进入此目录:cd /home/jingguoliang/docker/tomcat_dockerfile
- 创建context.xml:touch context.xml
- 编写context.xml
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context reloadable="true"> <!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
--> <!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
--> </Context> - 创建tomcat-users.xml:touch tomcat-users.xml
- 编写tomcat-users.xml文件
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users>
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary. It is
strongly recommended that you do NOT use one of the users in the commented out
section below since they are intended for use with the examples web
application.
-->
<!--
NOTE: The sample user and role entries below are intended for use with the
examples web application. They are wrapped in a comment and thus are ignored
when reading this file. If you wish to configure these users for use with the
examples web application, do not forget to remove the <!.. ..> that surrounds
them. You will also need to set the passwords to something appropriate.
-->
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
<user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
<user username="role1" password="<must-be-changed>" roles="role1"/>
-->
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-gui" />
<role rolename="manager-script" />
<role rolename="manager-status" />
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="deploy" password="tomcat" roles="manager-gui,manager-script,manager-status" /> </tomcat-users> - 创建Dockerfile文件:touch Dockerfile(D要大写)
- 编写Dockerfile文件:vim Dockerfile 并保存。
# First docker file from jingguoliang
# VERSION 0.0.1
# Author: jingguoliang #基础镜像
FROM docker.io/tomcat:7 #作者
MAINTAINER jingguoliang <jixue_jing@163.com> #定义工作目录
ENV WORK_PATH /usr/local/tomcat/conf #定义要替换的tomcat-users.xml文件名
ENV USER_CONF_FILE_NAME tomcat-users.xml
#定义要替换的context.xml文件名
ENV CONTEXT_CONF_FILE_NAME context.xml #删除tomcat原文件tomcat-users.xml
RUN rm $WORK_PATH/$USER_CONF_FILE_NAME
#删除tomcat原文件context.xml
RUN rm $WORK_PATH/$CONTEXT_CONF_FILE_NAME #复制文件tomcat-users.xml到tomcat容器下; .代表当前目录,如果Dockerfile和tomcat-users.xml;context.xml不在同一目录,需要改变配置文件路径
COPY ./$USER_CONF_FILE_NAME $WORK_PATH/
#复制文件context.xml到tomcat容器下
COPY ./$CONTEXT_CONF_FILE_NAME $WORK_PATH/- From:我们将要在哪个镜像进行操作,使用格式为 From "镜像名称:版本"
- MAINTAINER:制作者,使用格式为 MAINTAINER "作者名称" <"邮箱"”>
- 工作目录:此工作目录为Docker中的tomcat容器的配置文件的目录
- ENV:定义变量,使用格式为 ENV "变量名称" "变量值"
- RUN:执行命令,使用格式为 RUN "命令"
- 引用变量:$+"已经定义的变量名称",如:$WORK_PATH
- 执行Dockerfile:docker build -t tomcat7:v1 . 如下图所示
- tomcat7:7 新构建的镜像名称:镜像标签
- . 当前目录
- 成功后查看镜像文件:docker images,如下图
- 创建一个目录用来存放所需文件
- 制作镜像完成
- 原因:项目进行远程自动发布需要修改tomcat的配置文件,文件修改后一定要重新构建一个新的镜像,通过这个镜像创建容器运行。
- 启动容器
- 执行命令启动容器:docker run -itd -p 8070:8080 --name tomcat7 --privileged=true tomcat7:v1
- 查看启动的容器:docker ps ,如下图
- 访问容器:http://localhost:8070/manager,输入用户名、密码可以通过验证,进入如下页面
- 完成。
CentOS7下Docker中构建可以自动发布到项目的Tomcat容器的更多相关文章
- CentOS7下Docker中构建Jenkins容器
背景 在CentOS搭建Docker完成后,我们需要在Docker中搭建Jenkins用来实现工程自动部署. 安装前提 jdk已安装,安装目录如:usr/java/jdk1.8.0_161 maven ...
- Docker-通过docker-maven-plugin插件实现docker镜像构建并自动发布到远程docker服务器
我们知道,docker能实现应用打包隔离,实现快速部署和迁移.如果我们开发应用使用了spring cloud + spring boot架构,那么,通过docker-maven-plugin实现快速构 ...
- 将自己的SpringBoot应用打包发布到Linux下Docker中
目录 将自己的SpringBoot应用打包发布到Linux下Docker中 1. 环境介绍 2. 开始前的准备 2.1 开启docker远程连接 2.2 新建SpringBoot项目 3. 开始构建我 ...
- centos7下docker的安装教程
Centos7下docker安装教程以及踩过的那些坑 推荐在Centos下安装docker,在windows下安装docker可能会遇到很多的问题,而且docker官方推荐使用linux环境来使用do ...
- centos7下docker发布第一个微服务应用(Eureka)
1.在windows下打包 微服务应用通过maven进行打包,在项目的pom.xml执行mvn clean package,或者直接通过idea或者eclipse进行maven打包 之上操作将在项目的 ...
- CentOS7下Docker的安装与使用
前言 简介 Docker 是一个开源的应用容器引擎,基于 Go 语言,并遵从 Apache2.0 协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到 ...
- CentOS7 下Docker最新入门教程 超级详细 (安装以及简单的使用)
转载https://blog.csdn.net/wzsy_ll/article/details/82866627 1.为什么使用Docker(本人) 最近总是频繁的在新服务器发布项目, 每次发布都需要 ...
- Windows下配置Jenkins 实现自动发布maven项目至tomcat(svn+maven+tomcat)
Jenkins安装完成之后,需要我们对其配置,然后才可以实现自动部署项目. 前提 防火墙开放tomcat的8080端口 Linux(CentOS):firewall-cmd --zone=public ...
- Linux下docker中安装宝塔面板教程
本人云服务器,装的cent os7.6,在cent os7.6已装了docker,没装的可以借鉴 https://www.cnblogs.com/xiaoyige/p/12673076.html 1. ...
随机推荐
- node+react 打包成功,控制台报错
控制台报错: 'ReactCurrentOwner' of undefined 解决办法:RN版本的问题. As I mentioned, make sure you've installed the ...
- 软工网络15团队作业4——Alpha阶段敏捷冲刺7.0
1.每天举行站立式会议,提供当天站立式会议照片一张. 2.项目每个成员的昨天进展.存在问题.今天安排. 成员 昨天已完成 今天计划完成 郭炜埕 实现前端各界面的跳转连接 学习后端相关知识 郑晓丽 完善 ...
- STL之Deque容器
1.Deque容器 1)deque是“double-ended queue”的缩写,和vector一样都是STL的容器,deque是双端数组,而vector是单端的. 2)deque在接口上和vect ...
- centos下jdk、jre安装
1.在/usr/目录下创建java目录 [root@localhost ~]# mkdir/usr/java [root@localhost ~]# cd /usr/java 2.下载jdk,然后解压 ...
- 【转】 如何导入excel数据到数据库,并解决导入时间格式问题
在办公环境下,经常会用到处理excel数据,如果用写程序导入excel数据到数据库那就太麻烦了,涉及解析excel,还要各种格式问题,下面简单利用数据库本身支持的功能解决这类导入问题. 准备 创建表 ...
- [openjudge-动态规划]怪盗基德的滑翔翼
题目描述 描述 怪盗基德是一个充满传奇色彩的怪盗,专门以珠宝为目标的超级盗窃犯.而他最为突出的地方,就是他每次都能逃脱中村警部的重重围堵,而这也很大程度上是多亏了他随身携带的便于操作的滑翔翼. 有一天 ...
- Base64图片编码原理,base64图片工具介绍,图片在线转换Base64
Base64图片编码原理,base64图片工具介绍,图片在线转换Base64 DataURI 允许在HTML文档中嵌入小文件,可以使用 img 标签或 CSS 嵌入转换后的 Base64 编码,减少 ...
- linux java -version 和 javac -version 不一致
我是在6 的基础上又装了一个 8. 结果java -v 和 javac -v的 一个显示 6 一个显示8 解决方式: 再次source 一下配置文件 如: source ~/.bashrc 或者 ...
- 线程安全的CopyOnWriteArrayList
证明CopyOnWriteArrayList是线程安全的 先写一段代码证明CopyOnWriteArrayList确实是线程安全的. ReadThread.java import java.util. ...
- linux python虚拟环境 相关的
为什么要用虚拟环境 在使用python开发过程中,各种业务需求多了,导致工程任务多了,难免会碰到不同的工程依赖不同版本库的问题,;或者是在开发的时候不想让物理环境里充斥各种各样的库,引发依赖环境灾难, ...