docker镜像上传到阿里仓库,并在服务器pull拉取运行

阿里云的镜像仓库目前免费。可以设置私有或者公开。

如图,在弹性计算分类中:

进去按照步骤申请命名空间和镜像。

 

剩下的操作非常简单,阿里云上教程也非常详细。

 

阿里云后台会给一个镜像的公网地址和公网域名,将公网域名添加到我们客户端的镜像加速里。

在docker客户端执行登录命令:

docker login --username=账号registry.cn-beijing.aliyuncs.com

输入密码

准备上传镜像:运行docker images

$ docker images
REPOSITORY                                   TAG                 IMAGE ID            CREATED             SIZE
web_hello_woeld                              latest              5f7396b0ee3a        3 hours ago         138MB
nginx                                        latest              5a3221f0137b        3 weeks ago         126MB
openjdk                                      8-jdk-alpine        a3562aa0b991        4 months ago        105MB
hello-world                                  latest              fce289e99eb9        8 months ago        1.84kB

使用docker tag命令
Admin@▒ߺ▒▒▒ MINGW64 /d/apache-maven-3.5.3/package/com/zhl/web_hello_world/0.0.1
$ docker tag 5f7396b0ee3a registry.cn-beijing.aliyuncs.com/命名空间/镜像名称:latest

将本地镜像push到阿里云
Admin@▒ߺ▒▒▒ MINGW64 /d/apache-maven-3.5.3/package/com/zhl/web_hello_world/0.0.1
$ docker push registry.cn-beijing.aliyuncs.com/命名空间/镜像名称:latest
The push refers to repository [registry.cn-beijing.aliyuncs.com/命名空间/镜像名称]
629f759b402b: Pushed
ca5d0683bff4: Pushed
ceaf9e1ebef5: Layer already exists
9b9b7f3d56a0: Layer already exists
f1b5933fe4b5: Layer already exists
latest: digest: sha256:7b617e0bad9ab980acb5972db28cd3902f3769b5d3b56e6603def8386200f7c9 size: 1371

此时上传镜像就完成了,接下来我们打开linux服务器,准备拉取镜像并运行。

还是同样的登录命令,在linux上登录到阿里云仓库:

docker login --username=账号registry.cn-beijing.aliyuncs.com

此时注意,要在linux机子上添加仓库的加速,阿里的后台有。按我的实际网络环境看,反正很卡。

拉取镜像:

sudo docker pull registry.cn-beijing.aliyuncs.com/命名空间/镜像名称:[镜像版本号]

pull到本地也有点慢,

[root@centos7641 system]# docker pull registry.cn-beijing.aliyuncs.com/avi/study:2
2: Pulling from avi/study
Digest: sha256:a84af1acac6f73c8ce686ccf085717ce7e980c5de1cd7c73e303f0c83680b843
Status: Downloaded newer image for registry.cn-beijing.aliyuncs.com/avi/study:2
registry.cn-beijing.aliyuncs.com/avi/study:2
[root@centos7641 system]# docker images
REPOSITORY                                   TAG                 IMAGE ID            CREATED             SIZE
registry.cn-beijing.aliyuncs.com/命名空间/镜像名称              镜像版本号              5f7396b0ee3a         3 hours ago         138MB
httpd                                        latest              7d85cc3b2d80        2 weeks ago         154MB
nginx                                        latest              5a3221f0137b        3 weeks ago         126MB
php                                          5.6-fpm             3458979c7744        7 months ago        344MB
hello-world                                  latest              fce289e99eb9        8 months ago        1.84kB
training/webapp                              latest              6fae60ef3446        4 years ago         349MB

运行:

docker run -d --name study1 -v /data/log/:/data/log/ -p 8081:8080 registry.cn-beijing.aliyuncs.com/命名空间/镜像名称:镜像版本号

这里我使用了-v命令映射了本地目录和容器目录,因为我的springboot项目的application.properties中配置的:

logging.path=/data/log/

所以这个地址,按照自己实际项目处理即可
我的这个linux机子ip是:192.168.145.132,所以此时在浏览器访问:http://192.168.145.132:8081/ 就能看到我的测试项目的页面。
使用tail命令查看日志:

[root@centos7641 log]# tail -f /data/log/spring.log
2019-09-08 12:03:43.931  INFO 1 --- [main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-09-08 12:03:43.932  INFO 1 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-08 12:03:44.081  INFO 1 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-09-08 12:03:44.081  INFO 1 --- [main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2046 ms
2019-09-08 12:03:44.490  INFO 1 --- [main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-08 12:03:44.871  INFO 1 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-09-08 12:03:44.883  INFO 1 --- [main] c.z.w.WebHelloWorldApplication           : Started WebHelloWorldApplication in 3.804 seconds (JVM running for 4.404)
2019-09-08 12:04:26.556  INFO 1 --- [http-nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-09-08 12:04:26.556  INFO 1 --- [http-nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-09-08 12:04:26.560  INFO 1 --- [http-nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 4 ms

要发表评论,您必须先登录