问题描述

今天在本地修改了代码,通过docker上传后,却发现代码不是最新的,启动监听的端口也不对.

查看启动日志,发现里面的jar包名称也不对.

2019-05-23 02:44:56.959 [main] TRACE Application - {
# application.conf @ jar:file:/app/ktor-sample-1.0.0.jar!/application.conf: 6
"application" : {
# application.conf @ jar:file:/app/ktor-sample-1.0.0.jar!/application.conf: 7
"modules" : [
# application.conf @ jar:file:/app/ktor-sample-1.0.0.jar!/application.conf: 7
"com.cxyzy.ktor.demo.ApplicationKt.module"
]
},
# application.conf @ jar:file:/app/ktor-sample-1.0.0.jar!/application.conf: 2
"deployment" : {
# application.conf @ jar:file:/app/ktor-sample-1.0.0.jar!/application.conf: 3
"port" : 8080,
# application.conf @ jar:file:/app/ktor-sample-1.0.0.jar!/application.conf: 4
"watch" : [
# application.conf @ jar:file:/app/ktor-sample-1.0.0.jar!/application.conf: 4
"kotlin-ktor-mongo-sample"
]
},
# Content hidden
"security" : "***"
}

2019-05-23 02:44:57.381 [main] DEBUG Application - Java Home: /opt
2019-05-23 02:44:57.382 [main] DEBUG Application - Class Loader: jdk.internal.loader.ClassLoaders$AppClassLoader@55054057: []
2019-05-23 02:44:57.391 [main] INFO Application - No ktor.deployment.watch patterns match classpath entries, automatic reload is not active
2019-05-23 02:44:58.909 [main] INFO Application - Responding at http://0.0.0.0:8080
2019-05-23 02:44:58.909 [main] INFO Application - Application started: io.ktor.application.Application@36ac8a63

编译及上传、下载docker包步骤
  1. 本地编译并打tag
    gradle build -x test
    docker build -t shell_note_server .
    docker tag ktor-sample:latest registry.cn-hangzhou.aliyuncs.com/cxyzy/shell_note_server:1.0.1
  2. 登陆并上传
    docker login --username=阿里云用户ID registry.cn-hangzhou.aliyuncs.com
    docker push registry.cn-hangzhou.aliyuncs.com/cxyzy/shell_note_server:1.0.1
  3. 在服务拉取镜像并启动
    先切换到root用户下,再执行如下命令:
    docker login --username=阿里云用户ID registry.cn-hangzhou.aliyuncs.com
    docker pull registry.cn-hangzhou.aliyuncs.com/cxyzy/shell_note_server:1.0.1
    docker run -m512M --cpus 1 -it -p 80:8080 -p 443:8443 --rm registry.cn-hangzhou.aliyuncs.com/cxyzy/shell_note_server:1.0.1
原因

在本地打tag的步骤错了,下面的ktor-sample是我之前写的一个demo,应该更新为本次的shell_note_server

docker tag ktor-sample:latest registry.cn-hangzhou.aliyuncs.com/cxyzy/shell_note_server:1.0.1

修改后:

docker tag shell_note_server:latest registry.cn-hangzhou.aliyuncs.com/cxyzy/shell_note_server:1.0.1

重复之后该步骤后续步骤,搞定.