Oracle
用teleDB
,都在容器上部署,所以系统的学习下,之前着急忙慌的。实战类
,适用于小白我所渴求的无非是将心中脱颖欲出的本性付诸生活。为什么竟如此艰难呢?----黑塞
Docker
是运行在Linux
上的所以需要安装虚拟机,win10 默认有Hyper-V
,不需要安装,还需要安装一个Linux
内核,可以参考适用于 Linux 的 Windows 子系统安装指南 (Windows 10)WSL允许您直接在Windows上运行Linux环境(包括命令行工具和应用程序),而不需要传统虚拟机或双引导设置的开销。WSL特别有助于web开发人员以及使用Bash和linux优先工具(例如。Ruby, Python)在Windows上使用它们的工具链,并确保开发环境和生产环境之间的一致性。当您在Windows上安装Linux版本时,您将获得一个完整的Linux环境。WsL1与Windows是隔离的- Ul是终端,你可以安装工具。在不修改或中断Windows安装的情况下,将语言和编译器导入Linux环境。我们推荐使用WsL2。
完成上述步骤之后,可以启动docker
:
##这是一个基本docker教程
git clone https://github.com/docker/getting-started.git
cd getting-started
docker build -t docker101tutorial .
之后启动点击restart
完成Dokcer启动
PS C:\Users\lenovo> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
PS C:\Users\lenovo> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
uname -r
或者cat /proc/version
yum remove -y firewalld-*
yum install docker
/etc/sysctl.conf net.ipv4.ip_forward=1
使用sysctl -p
让配置立刻生效(否则需要重新虚拟机)docker是通过虚拟交互机来进行通讯的,需要开启路由转发的功能。软件的 BUG
: iptables -nL FORWARD
版本 大于 1.12 时会设置 FORWARD
的默认规则,被设置为 DROP
,对于有些docker的版本中,FORWARD
链的规则被设置成了DROP
,会造成容器和宿主机之间无法通讯。
解决办法:修改 /lib/systemd/system/docker.server
重载配置文件,重启服务
systemctl daemon-reload
systemctl restart docker
PS E:\docker> docker pull docker.io/mamohr/centos-java
Using default tag: latest
latest: Pulling from mamohr/centos-java
469cfcc7a4b3: Pull complete
6c9a0d503960: Pull complete
Digest: sha256:11988ca920fe0a3f3dd382b62690d993e843b668b1fb7f31142494f1e7b5d136
Status: Downloaded newer image for mamohr/centos-java:latest
docker.io/mamohr/centos-java:latest
PS E:\docker> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 300e315adb2f 7 months ago 209MB
mamohr/centos-java latest e041132b8b32 3 years ago 577MB
docker run -it --privileged mamohr/centos-java:latest /usr/sbin/init
# 进入容器
docker exec -it f6209e004f2f /bin/bash
[root@f6209e004f2f /]# cd /tmp/;wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.69/bin/apache-tomcat-8.5.69.tar.gz
--2021-07-27 02:52:02-- https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.69/bin/apache-tomcat-8.5.69.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 101.6.8.193, 2402:f000:1:408:8100::1, ...
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10561246 (10M) [application/octet-stream]
Saving to: 'apache-tomcat-8.5.69.tar.gz'
100%[==================================================================================>] 10,561,246 7.44MB/s in 1.4s
2021-07-27 02:52:07 (7.44 MB/s) - 'apache-tomcat-8.5.69.tar.gz' saved [10561246/10561246]
[root@f6209e004f2f tmp]# tar -zxvf apache-tomcat-8.5.69.tar.gz
[root@f6209e004f2f tmp]# ls
apache-tomcat-8.5.69 apache-tomcat-8.5.69.tar.gz hsperfdata_root ks-script-hE5IPf yum.log
[root@f6209e004f2f tmp]# mkdir /usr/tomcat8.5 ; mv apache-tomcat-8.5.69 /usr/tomcat8.5
[root@f6209e004f2f tmp]# cd /usr/tomcat8.5/
[root@f6209e004f2f tomcat8.5]# ls
apache-tomcat-8.5.69
[root@f6209e004f2f tomcat8.5]# chown -hR tomcat:tomcat apache-tomcat-8.5.69
chown: invalid user: 'tomcat:tomcat'
#create tomcat user and group
[root@f6209e004f2f tomcat8.5]# groupadd tomcat;useradd -g tomcat -s /sbin/nologin tomcat
[root@f6209e004f2f tomcat8.5]# chown -hR tomcat:tomcat apache-tomcat-8.5.69
vim /lib/systemd/system/tomcat.service
#=====
[Unit]
Description=Apache Tomcat 8.5
After=syslog.target network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment=JAVA_HOME=/usr/java/latest/jre
## tomcat as link -s
Environment=CATALINA_PID=/usr/tomcat8.5/apache-tomcat-8.5.69/temp/tomcat.pid
Environment=CATALINA_HOME=/usr/tomcat8.5/apache-tomcat-8.5.69
Environment=CATALINA_BASE=/usr/tomcat8.5/apache-tomcat-8.5.69
Environment='CATALINA_OPTS=-Xms512M -Xmx4096M -server -XX:+UseParallelGC'
Environment='CATALINA_OPTS=-Dfile.encoding=UTF-8 -server -Xms2048m -Xmx2048m -Xmn1024m -XX:SurvivorRatio=10 -XX:MaxTenuringThreshold=15 -XX:NewRatio=2 -XX:+DisableExplicitGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/usr/tomcat8.5/apache-tomcat-8.5.69/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@cdd43dfcdf88 system]# systemctl daemon-reload
[root@cdd43dfcdf88 system]# systemctl start tomcat
[root@cdd43dfcdf88 system]#
[root@cdd43dfcdf88 system]# systemctl enable tomcat
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /usr/lib/systemd/system/tomcat.service.
[root@cdd43dfcdf88 system]#
[root@cdd43dfcdf88 system]# systemctl status tomcat
● tomcat.service - Apache Tomcat 8.5
Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-07-27 08:24:19 UTC; 18s ago
Process: 1179 ExecStart=/usr/tomcat8.5/apache-tomcat-8.5.69/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 1186 (java)
CGroup: /docker/cdd43dfcdf8828b963c7b761ba2301fbd14643d99a44232badefa0a641fde60b/system.slice/tomcat.service
└─1186 /usr/java/latest/jre/bin/java -Djava.util.logging.config.file=/usr/tomcat8.5/apache-tomcat-8.5.69/conf/logging.properties -Djava.util....
‣ 1186 /usr/java/latest/jre/bin/java -Djava.util.logging.config.file=/usr/tomcat8.5/apache-tomcat-8.5.69/conf/logging.properties -Djava.util....
Jul 27 08:24:18 cdd43dfcdf88 systemd[1]: Starting Apache Tomcat 8.5...
Jul 27 08:24:19 cdd43dfcdf88 systemd[1]: Started Apache Tomcat 8.5.
[root@cdd43dfcdf88 system]# curl http://127.0.0.1:8080
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Apache Tomcat/8.5.69</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="tomcat.css" rel="stylesheet" type="text/css" />
</head>
.。。。。
[root@cdd43dfcdf88 bin]# systemctl start tomcat
Job for tomcat.service failed because the control process exited with error code. See "systemctl status tomcat.service" and "journalctl -xe" for details.
## 日志消息写到文本里,在文本里排查问题:cat log | grep tomcat
journalctl -xe >> log
[root@f6209e004f2f /]# yum clean all
Loaded plugins: fastestmirror, ovl
Cleaning repos: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@f6209e004f2f /]# exit
exit
PS E:\docker> docker commit cdd43dfcdf88 centos7_java8_tomcat8.5:latest
sha256:b8c89e810729ae3f9870bac9273f883f9f0bb5ca88ffec7b84f88b64451d805b
PS E:\docker> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_java8_tomcat8.5 latest b8c89e810729 7 seconds ago 700MB
centos7_java8_tomcat8.5_base latest e9e848ab97f6 2 hours ago 679MB
centos latest 300e315adb2f 7 months ago 209MB
mamohr/centos-java latest e041132b8b32 3 years ago 577MB
hub.c.163.com/housan993/centos7_jdk8 latest 0f793ba5281b 3 years ago
docker> docker run -it --privileged mamohr/centos-java:latest /usr/sbin/init
PS E:\docker> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7_java8_tomcat8.5 latest b8c89e810729 39 minutes ago 700MB
centos7_java8_tomcat8.5_base latest e9e848ab97f6 3 hours ago 679MB
centos latest 300e315adb2f 7 months ago 209MB
mamohr/centos-java latest e041132b8b32 3 years ago 577MB
hub.c.163.com/housan993/centos7_jdk8 latest 0f793ba5281b 3 years ago 356MB
PS E:\docker> docker save centos7_java8_tomcat8.5:latest -o centos7_java8_tomcat8.5.tar
这里的话,我们用之前的一個镜像為基础镜像。发布一个web应用。如果有使用docker客户端工具,那么每次可以远程直接替换,war实现部署, UAWeb.war 是我们自己的应用war包。
Dockerfile
文件:FROM centos7_java8_tomcat8.5:latest
MAINTAINER LIRUILONG
COPY UAWeb.war /usr/tomcat8.5/apache-tomcat-8.5.69/webapps/UAWeb.war
EXPOSE 8080
docker build -t uag_image .
# 给一下权限
chmod 777 /usr/tomcat8.5/apache-tomcat-8.5.69/logs
docker run -it -v /logs:/usr/tomcat8.5/apache-tomcat-8.5.69/logs --privileged uag_image:latest /usr/sbin/init
docker run -it -v /logs:/usr/tomcat8.5/apache-tomcat-8.5.69/logs -p 9090:8080 --privileged uag_image:latest /usr/sbin/init