docker 部署服务实例

简介: 使用docker 部署服务实例案例

docker 部署 nginx

1、下载nginx ,并运行nginx容器

docker search nginx
  
# 注意 run 的镜像不存在,会自动下载
docker run -d --name nginx01 -p 6666:80 nginx

-it 交互式进入容器
-d 后台方式允许
--name 容器命名
-p 向主机暴露端口   主机端口:容器端口
[root@VM-8-9-centos ~]# docker run -d --name nginx01 -p 6666:80 nginx
b2a09893d3ab15e83517cd30dd2bd6dd563fb126d9b9a014af6167e0cb1c4f8b
[root@VM-8-9-centos ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                   NAMES
b2a09893d3ab   nginx     "/docker-entrypoint.…"   23 seconds ago   Up 23 seconds   0.0.0.0:6666->80/tcp, :::6666->80/tcp   nginx01

2、测试nginx

[root@VM-8-9-centos ~]# curl localhost:6666
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

3、以一个新的终端方式交互式进入容器

# 查看当前正在运行的容器
[root@VM-8-9-centos ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
b2a09893d3ab   nginx     "/docker-entrypoint.…"   4 minutes ago   Up 4 minutes   0.0.0.0:6666->80/tcp, :::6666->80/tcp   nginx01

# 进入容器
[root@VM-8-9-centos ~]# docker exec -it nginx01 /bin/bash
root@b2a09893d3ab:/# 

操作容器。。。。

docker部署tomcat

1、下载镜像

docker pull tomcat9.0.48-jdk8-adoptopenjdk-openj9

2、查看下载的镜像

[root@VM-8-9-centos ~]# docker images
REPOSITORY   TAG                               IMAGE ID       CREATED        SIZE
tomcat       9.0.48-jdk8-adoptopenjdk-openj9   d716ed54947b   6 hours ago    386MB
nginx        latest                            d1a364dc548d   3 weeks ago    133MB
mysql        8.0.25                            c0cdc95609f1   5 weeks ago    556MB
centos       latest                            300e315adb2f   6 months ago   209MB

3、运行容器

[root@VM-8-9-centos ~]# docker run -d --name tomcat01 -p 6666:8080 d716ed54947b
9af883046bff06510901fe15b87cd0ea3134f43f91eedaf0019cb6b17df77932
[root@VM-8-9-centos ~]# docker ps
CONTAINER ID   IMAGE          COMMAND             CREATED          STATUS          PORTS                                       NAMES
9af883046bff   d716ed54947b   "catalina.sh run"   11 seconds ago   Up 10 seconds   0.0.0.0:6666->8080/tcp, :::6666->8080/tcp   tomcat01

4、查看容器日志

[root@VM-8-9-centos ~]# docker logs  --tail 1000 9af883046bff
17-Jun-2021 06:58:36.285 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/9.0.48
17-Jun-2021 06:58:36.286 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 10 2021 09:22:01 UTC
17-Jun-2021 06:58:36.287 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.48.0
17-Jun-2021 06:58:36.287 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
17-Jun-2021 06:58:36.287 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-1127.19.1.el7.x86_64
17-Jun-2021 06:58:36.287 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
17-Jun-2021 06:58:36.287 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /opt/java/openjdk/jre
17-Jun-2021 06:58:36.287 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_292-b10
17-Jun-2021 06:58:36.287 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Eclipse OpenJ9
17-Jun-2021 06:58:36.287 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
17-Jun-2021 06:58:36.288 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
17-Jun-2021 06:58:36.290 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xoptionsfile=/opt/java/openjdk/jre/lib/amd64/default/options.default
17-Jun-2021 06:58:36.290 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xlockword:mode=default,noLockword=java/lang/String,noLockword=java/util/MapEntry,noLockword=java/util/HashMap$Entry,noLockword=org/apache/harmony/luni/util/ModifiedMap$Entry,noLockword=java/util/Hashtable$Entry,noLockword=java/lang/invoke/MethodType,noLockword=java/lang/invoke/MethodHandle,noLockword=java/lang/invoke/CollectHandle,noLockword=java/lang/invoke/ConstructorHandle,noLockword=java/lang/invoke/ConvertHandle,noLockword=java/lang/invoke/ArgumentConversionHandle,noLockword=java/lang/invoke/AsTypeHandle,noLockword=java/lang/invoke/ExplicitCastHandle,noLockword=java/lang/invoke/FilterReturnHandle,noLockword=java/lang/invoke/DirectHandle,noLockword=java/lang/invoke/ReceiverBoundHandle,noLockword=java/lang/invoke/DynamicInvokerHandle,noLockword=java/lang/invoke/FieldHandle,noLockword=java/lang/invoke/FieldGetterHandle,noLockword=java/lang/invoke/FieldSetterHandle,noLockword=java/lang/invoke/StaticFieldGetterHandle,noLockword=java/lang/invoke/StaticFieldSetterHandle,noLockword=java/lang/invoke/IndirectHandle,noLockword=java/lang/invoke/InterfaceHandle,noLockword=java/lang/invoke/VirtualHandle,noLockword=java/lang/invoke/PrimitiveHandle,noLockword=java/lang/invoke/InvokeExactHandle,noLockword=java/lang/invoke/InvokeGenericHandle,noLockword=java/lang/invoke/VarargsCollectorHandle,noLockword=java/lang/invoke/ThunkTuple
17-Jun-2021 06:58:36.290 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xjcl:jclse29
17-Jun-2021 06:58:36.291 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.ibm.oti.vm.bootstrap.library.path=/opt/java/openjdk/jre/lib/amd64/default:/opt/java/openjdk/jre/lib/amd64
17-Jun-2021 06:58:36.291 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dsun.boot.library.path=/opt/java/openjdk/jre/lib/amd64/default:/opt/java/openjdk/jre/lib/amd64
17-Jun-2021 06:58:36.291 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.library.path=/opt/java/openjdk/jre/lib/amd64/default:/opt/java/openjdk/jre/lib/amd64:/usr/local/tomcat/native-jni-lib:/usr/lib64:/usr/lib
17-Jun-2021 06:58:36.291 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.home=/opt/java/openjdk/jre
17-Jun-2021 06:58:36.291 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.ext.dirs=/opt/java/openjdk/jre/lib/ext
17-Jun-2021 06:58:36.291 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Duser.dir=/usr/local/tomcat
17-Jun-2021 06:58:36.291 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:+IgnoreUnrecognizedVMOptions
17-Jun-2021 06:58:36.292 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:+IdleTuningGcOnIdle
17-Jun-2021 06:58:36.292 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xshareclasses:name=openj9_system_scc,cacheDir=/opt/java/.scc,readonly,nonFatal
17-Jun-2021 06:58:36.292 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.class.path=.
17-Jun-2021 06:58:36.293 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
17-Jun-2021 06:58:36.293 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
17-Jun-2021 06:58:36.293 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
17-Jun-2021 06:58:36.293 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
17-Jun-2021 06:58:36.293 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
17-Jun-2021 06:58:36.293 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
17-Jun-2021 06:58:36.293 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.class.path=/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
17-Jun-2021 06:58:36.293 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
17-Jun-2021 06:58:36.293 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
17-Jun-2021 06:58:36.294 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
17-Jun-2021 06:58:36.294 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dsun.java.command=org.apache.catalina.startup.Bootstrap start
17-Jun-2021 06:58:36.294 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dsun.java.launcher=SUN_STANDARD
17-Jun-2021 06:58:36.294 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dsun.java.launcher.pid=1
17-Jun-2021 06:58:36.297 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.30] using APR version [1.6.5].
17-Jun-2021 06:58:36.297 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
17-Jun-2021 06:58:36.297 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
17-Jun-2021 06:58:36.299 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1f  31 Mar 2020]
17-Jun-2021 06:58:36.479 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
17-Jun-2021 06:58:36.491 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [311] milliseconds
17-Jun-2021 06:58:36.510 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
17-Jun-2021 06:58:36.510 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.48]
17-Jun-2021 06:58:36.516 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
17-Jun-2021 06:58:36.524 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [32] milliseconds

5、外部访问

在这里插入图片描述

进入容器 拷贝webapps.dist目录内容 到 webapps目录下即可

[root@VM-8-9-centos ~]# docker exec -it tomcat01 /bin/bash

[root@VM-8-9-centos ~]#  cp -r ../webapps.dist/* ./

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eeFvHXRn-1624330672107)(C:\Users\Meet\AppData\Roaming\Typora\typora-user-images\image-20210618111208095.png)]

配置docker镜像加速

地址:https://cr.console.aliyun.com

1、创建镜像仓库

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5oYdbIzv-1624330672111)(C:\Users\Meet\AppData\Roaming\Typora\typora-user-images\image-20210617144839079.png)]

根据需求创建 个人版 还是 企业版

2、为自己服务器的docker配置镜像加速

在这里插入图片描述

# 创建docker配置目录
sudo mkdir -p /etc/docker
sudo vim /etc/docker/daemon.json 
# 添加这一行
{
  "registry-mirrors": ["加速器地址"]
}
# 重启docker
sudo systemctl daemon-reload
sudo systemctl restart docker
相关文章
|
14天前
|
人工智能 API 数据安全/隐私保护
使用 Docker 一键免费部署 63.8k 的私人 ChatGPT 网页应用
NextChat 是一个可以在 GitHub 上一键免费部署的私人 ChatGPT 网页应用,支持 GPT3、GPT4 和 Gemini Pro 模型。该项目在 GitHub 上获得了 63.8k 的 star 数。部署简单,只需拉取 Docker 镜像并运行容器,设置 API Key 后即可使用。此外,NextChat 还提供了预设角色的面具功能,方便用户快速创建对话。
81 22
使用 Docker 一键免费部署 63.8k 的私人 ChatGPT 网页应用
|
25天前
|
SQL 关系型数据库 数据库
国产数据实战之docker部署MyWebSQL数据库管理工具
【10月更文挑战第23天】国产数据实战之docker部署MyWebSQL数据库管理工具
84 4
国产数据实战之docker部署MyWebSQL数据库管理工具
|
15天前
|
运维 开发者 Docker
Docker Compose:简化容器化应用的部署与管理
Docker Compose:简化容器化应用的部署与管理
|
15天前
|
Docker 微服务 容器
使用Docker Compose实现微服务架构的快速部署
使用Docker Compose实现微服务架构的快速部署
33 1
|
1月前
|
Web App开发 前端开发 测试技术
【Docker项目实战】使用docker部署tabler后台模版
【10月更文挑战第10天】使用docker部署tabler后台模版
42 1
【Docker项目实战】使用docker部署tabler后台模版
|
1月前
|
JSON JavaScript 测试技术
【Docker项目实战】使用Docker部署PPTist在线演示文稿应用
【10月更文挑战第9天】使用Docker部署PPTist在线演示文稿应用
42 1
【Docker项目实战】使用Docker部署PPTist在线演示文稿应用
|
1月前
|
消息中间件 编解码 Docker
【Docker项目实战】Docker部署RabbitMQ消息中间件
【10月更文挑战第8天】Docker部署RabbitMQ消息中间件
97 1
【Docker项目实战】Docker部署RabbitMQ消息中间件
|
1月前
|
存储 前端开发 测试技术
【Docker项目实战】使用Docker部署Calcium网页计算器
【10月更文挑战第7天】使用Docker部署Calcium网页计算器
37 1
【Docker项目实战】使用Docker部署Calcium网页计算器
|
29天前
|
负载均衡 应用服务中间件 网络安全
docker swarm添加更多的服务
【10月更文挑战第16天】
21 6
|
29天前
|
Docker 容器
docker swarm启动服务并连接到网络
【10月更文挑战第16天】
27 5
下一篇
无影云桌面