您现在的位置是:热点 >>正文
云计算核心技术Docker教程:Java镜像在容器中运行数据库
热点603912人已围观
简介...
首先,我们将看看在容器中运行数据库,以及我们如何使用卷和网络来持久化我们的数据并允许我们的应用程序与数据库对话。然后我们将把所有东西放在一个 Compose 文件中,它允许我们用一个命令设置和运行本地开发环境。最后,我们将看看将调试器连接到我们在容器内运行的应用程序。
无需下载 MySQL、安装、配置,然后将 MySQL 数云计据库作为服务运行,我们可以使用 MySQL 的 Docker 官方镜像并在容器中运行它。
在容器中运行 MySQL 之前,我们将创建几个卷,Docker 可以管理这些卷来存储我们的持久数据和配置。让我们使用 Docker 提供的托管卷功能,而不是使用绑定挂载。您可以在我们的文档中阅读有关使用卷的所有信息。
现在让我们创建我们的卷。我们将为算核数据创建一个,为 MySQL 的配置创建一个。
$ docker volume create mysql_data
$ docker volume create mysql_config
现在我们将创建一个网络,我们的应用程序和数据库将使用该网络相互通信。该网络称为用户定义的桥接网络,它为我们提供了一个很好的 DNS 查找服务,我们可以在创建心技连接字符串时使用它。
$ docker network create mysqlnet
现在,让我们在容器中运行 MySQL 并附加到我们上面创建的卷和网络。Docker 从 Hub 拉取镜像并在本地运行。
$ docker run -it --rm -d -v mysql_data:/var/lib/mysql \
-v mysql_config:/et术Dc/mysql/conf.d \
--network mysqlnet \
--name mysqlserver \
-e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic \
-e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic \
-p 330oc6:3306 mysql:8.0.23
好的,现在我们有一个正在运行的 MySQL,让我们更新我们的 Dockerfile 以激活应用程序中定义的 MySQL Spring 配置文件,并从内存中的 H2 数据库切换到我们刚刚创建的 MySQL 服务器。
我们只需要添加 MySQL 配置文件作为CMD定义的参数。
CMD ["./mvnw", "spring-keboot:run", "-Dspring-boot.run.profiles=mysql"]
让我们建立我们的形象
$ docker build --tag java-docker .
现在,让我们运行我们的容器。这一次,我们需要设置MYSQL_URL环境变量,以便我们的应用程序知道使用什么连接字符串来访问数据库。我们将使用该docr教ker run命令执行此操作。
$ docker run --rm -d \
--name springboot-server \
--network mysqlnet \
-e MYSQL_URL=jdbc:mysql://mysqlserver/petclinic \
-p 8080:8080 java-docker
让我们测试一下我们的应用程序是否已连接到程:数据库并能够列出 Veterinarians。
$ curl --request GET \
--url http://localhost:8080/vets \
--header 'content-type: application/json'
您应该会从我们的服务中收到以下 json。
{"vetList":[{"id"Ja:1,"firstName":"James","lastName":"Carter","specialties":[],"nrOfSpecialties":0,"new":false},{"id":2,"firstName":"Helen","lastName":"Leary","specialties":[va123;"id":1,"name":"radiology","new":false}],"nrOfSpecialties":1,"new":false},{"id":3,"firstName":"Linda","lastName":"Douglas","specialties":[{"id":3镜像,"name":"dentistry","new":false},{"id":2,"name":"surgery","new":false}],"nrOfSpecialties":2,"new":false},{"id":4,"firstName":"Rafael","lastName":"Orte在容ga","specialties":[{"id":2,"name":"surgery","new":false}],"nrOfSpecialties":1,"new":false},{"id":5,"firstName":"Henry","lastName":"Stevens","specialtie器中s":[{"id":1,"name":"radiology","new":false}],"nrOfSpecialties":1,"new":false},{"id":6,"firstName":"Sharon","lastName":"Jenkins","specialties":[],"n运行rOfSpecialties":0,"new":false}]}
Tags:
相关文章
云计算开发:Python3数学函数floor()方法详解
热点描述 floor(x) 返回数字的下舍整数,小于或等于 x。 语法 以下是 floor() 方法的语法: import math math.floor( x ) 注意:floor()是不能直接访问的,...
【热点】
阅读更多标签: 索尼 LEGO 银座索尼公园 80周年
热点云梦级5月7日云梦级消息,索尼集团于5 月 7 日迎来创立 80 周年。为纪念这一重要里程碑,索尼现已在东京银座的 Ginza Sony Park 举办特别展览“100.80.60.展”。 据介绍,相...
【热点】
阅读更多标签: 安克创新 H股上市 毕马威 充电储能
热点云梦级11月13日云梦级消息,据深圳商报报道,日前,安克创新发布公告称,公司拟在境外发行境外上市股份(H股)并申请在港交所主板挂牌上市。安克创新表示,公司将充分考虑现有股东的利益和境内外资本市场的情况...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.paulaschoice.hk/zh_hant/catalogsearch/result/?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Rec
- https://www.solerpalau.com/en-en/catalogsearch/result/?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,EBF
- https://www.tmtpost.com/search?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,EI9
- https://www.jusoen.com/addreng.asp?p1=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】jOc
- https://www.schenckprocess.com/search?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,369
- https://www.welshmountainzoo.org/shop/index.php?routeproduct/search&tag=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,BZf
- https://www.youthforum.org/search-results?cx=4f5236218ab5e8ef9&ie=UTF-8&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,jSP
- https://www.universal-music.co.jp/?ID=1sIcckCTeBS8FjzCshAW9w53s8gr691o&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,X4v
- https://www.teamlab.art/pt/?submit=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,rcu
- https://m.shoppinghow.kakao.com/m/search/q/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】Xti
- https://www.maafushidive.com?collections?vendors?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Mkb
- https://www.reallywildbirdfood.co.uk/store/search?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,QCR
- https://search.danawa.com/dsearch.php?query=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】m9U
- https://www.mexperience.com/?T=1686132112324&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,YEC
- https://www.pearson.com/en-us/search.html?aq=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,IS6
- https://www.ushmm.org/search/results/?ID=8s0587Oi8UTv74zPPM4fuhwjNpe2hsEE&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,rrW
- https://www.ntv.co.jp/3min/search/?action=QUERY&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Qzj
- https://www.duksung.ac.kr/search/front/Search.jsp?qt=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】0J2
- https://www.varian.com/en-au/search?cat=113&search=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,tqA
- https://www.sensorshop24.de/catalogsearch/result/index/?type=132&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,aw8
- https://www.tiktok.com/tag/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,e4f
- https://www.writingforward.com/?action=SEARCH&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,xLM
- https://www.udc.co.uk/index.php?route=product/search&sort=p.price&order=DESC&tag=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,KRB
- https://www.metaltix.com/?view=tours&filter=search&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,A0H
- https://www.mintos.org/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,DRh
- https://www.partilerdunyasi.com/index.php?route=product/search&tag=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Pmp
- https://www.scivee.tv/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,eKC
- https://www.scq.ubc.ca/?page=2&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,zJk
- https://www.spoiledsweetboutique.com/search/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,iCr
- https://www.trockenmittel.ch/catalogsearch/result/?iC=ZM3&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,mNo
- https://www.stonerealestate.com.au/?cat=100&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,61e
- https://www.sogou.com/web?query=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,PDl
- https://www.springfieldlibrary.org/library/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,oJp
- https://www.flickr.com/photos/tags/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】vS2
- https://www.nextavenue.org/?action=QUERY&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,eHq
- https://www.nyif.com/catalogsearch/result/index/?f=sarbanesoxleyU&index=me_cms_pe&lit=20&mode=list&p=1&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,BkD
- https://www.pickett.co.uk/collections/vendors?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,wbq
- https://www.nyif.com/catalogsearch/result/?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,8xq
- https://www.rollingstone.it/?ID=DVMeu3AlmzZE1cuJ2FmgmO5TSCQRb3yh&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,7y0
- https://www.sbaad.no/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,9F1
- https://www.nytimes.com/search?dropmab=true&query=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,xk7
- https://www.yr.no/en/search?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,2Xg
- https://www.ushmm.org/search/results.php?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,soU
- https://www.nslcleaders.org/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,KS2
- https://www.repetto.jp/item/search?action=QUERY&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,My0
- https://www.quarterjacksurgery.co.uk/?AT=3rBy&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Nau
- https://www.simcoemuskokahealth.org/SearchResults.aspx?SearchQuery=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,vdo
- https://www.southmeadows.co.uk/2019/07/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,drb
- https://www.ussalabama.com/?action=CHECK&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,YFa
- https://www.kyuhoshi.com/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,qQI