跳到主要内容

实战:一键构建-推送镜像-2023.1.8(测试成功)

实战:一键构建-推送镜像-2023.1.8(测试成功)

image-20230107215844356

目录

[toc]

实验环境

docker 20.10.21
go version go1.19

实验软件

2023.1.8-docker构建镜像测试

image-20230108101127489

image-20230108101143283

1、前提条件

go环境和docker环境已经具备。

image-20230108092847491

2、当前项目环境

Dockerfile内容:

image-20230108093015403

build文件内容:

image-20230108093126719

3、开始构建

  • 下载代码
[root@docker ~]#mkdir admission-webhook && cd admission-webhook
[root@docker admission-webhook]#git clone https://github.com/cnych/admission-webhook-example.git
Cloning into 'admission-webhook-example'...
remote: Enumerating objects: 170, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 170 (delta 1), reused 5 (delta 1), pack-reused 159
Receiving objects: 100% (170/170), 229.27 KiB | 0 bytes/s, done.
Resolving deltas: 100% (88/88), done.
[root@docker admission-webhook]#cd admission-webhook-example/
[root@docker admission-webhook-example]#git checkout train4
Branch train4 set up to track remote branch train4 from origin.
Switched to a new branch 'train4'
  • 开始构建

可以看到,有报错:

[root@docker admission-webhook-example]#export DOCKER_USER=onlyonexl
[root@docker admission-webhook-example]#./build
go: k8s.io/api@v0.25.4 requires
github.com/stretchr/testify@v1.8.0: missing go.sum entry; to add it:
go mod download github.com/stretchr/testify
Sending build context to Docker daemon 348.2kB
Step 1/3 : FROM alpine:latest
latest: Pulling from library/alpine
59bf1c3509f3: Already exists
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Downloaded newer image for alpine:latest
---> c059bfaa849c
Step 2/3 : ADD admission-webhook-example /admission-webhook-example
ADD failed: file not found in build context or excluded by .dockerignore: stat admission-webhook-example: file does not exist
The push refers to repository [docker.io/onlyonexl/admission-webhook-example]
An image does not exist locally with the tag: onlyonexl/admission-webhook-example

image-20230108093556989

  • 好像是这里的问题哎……

image-20230108093947454

  • 测试方法1:(失败)

https://blog.csdn.net/u012275249/article/details/117296408

image-20230108094311566

失败:

image-20230108094354373

  • 测试方法2:(失败)

https://zhuanlan.zhihu.com/p/462402771

image-20230108094809197

失败:

image-20230108094758487

  • 总结:感觉是go的版本不一样导致的……

  • 项目的go版本:go 1.19

image-20230108095000743

而我的机器上go版本是:go 1.16.2

image-20230108095034836

  • 升级我的机器上的go版本

image-20230108095841764

  • 升级完go版本后,这里再次构建

image-20230108095950816

这里为什么会被拒绝了呢?(可能是要先手动登录一下自己的dockerhub呢……)

可以看到,这里的惊险已经构建好了:

image-20230108100046421

这里手动登录下自己的dockerhub账号:

image-20230108100335353

这补救推送成功了吗哈哈:

image-20230108100413390

关于我

我的博客主旨:

  • 排版美观,语言精炼;
  • 文档即手册,步骤明细,拒绝埋坑,提供源码;
  • 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!

🍀 微信二维码 x2675263825 (舍得), qq:2675263825。

image-20230107215114763

🍀 微信公众号 《云原生架构师实战》

image-20230107215126971

🍀 博客 www.onlyyou520.com

image-20230107215612315

image-20230107215651525

🍀 csdn https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

image-20230107215149885

🍀 知乎 https://www.zhihu.com/people/foryouone

image-20230107215203185

最后

好了,关于本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!