本文转自测试人社区,原文链接: https://ceshiren.com/t/topic/30824

1. 完成本地 hub 的搭建,并截图。

  • 适用docker pull 拉取registry镜像
  • 软件测试学习笔记丨构建自己定制化的Nginx并推送_软件测试

  • 启动容器,创建本地hub
root@VM-16-5-ubuntu:~# docker run -d -p 5000:5000 -v ./myregistry/local/registry:/var/lib/registry --restart=always --name registry registry:2
9f36d4b3fdd94cdc49074375738b6a0ea4f935462e80c9ca4c009368126d29db
  • 1.
  • 2.

软件测试学习笔记丨构建自己定制化的Nginx并推送_软件测试_02

2. 不使用挂载的方式,而是通过 Docker 制作的方式实现对 Nginx 的默认页的修改,把制作的 Dockerfile 和首页 html 传到代码仓。

  • 1.制作dockerfile:
root@VM-16-5-ubuntu:~/mydockerfile# cat Dockerfile 
FROM nginx:latest
COPY index.html /usr/share/nginx/html/
  • 1.
  • 2.
  • 3.
  • 2.指定index.html放入镜像中指定路径
root@VM-16-5-ubuntu:~/mydockerfile# cat index.html
<html>
<head>
    <meta charset="UTF8">
    <title>NGINX</title>
</head>
<h1>hello world,这是一个本地构建的NGINX服务</h1>
</html>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 3 适用docker build 生成镜像
  • 软件测试学习笔记丨构建自己定制化的Nginx并推送_html_03

  • 4 启动容器
  • 软件测试学习笔记丨构建自己定制化的Nginx并推送_docker_04

  • 5 访问容器地址,展示nginx内容

软件测试学习笔记丨构建自己定制化的Nginx并推送_nginx_05

3. 推送自己定制好的 Nginx 镜像到本地镜像仓库 hub 中,查询本地镜像仓库中的镜像截图。

  • 打标签,确定要推送的镜像标签
    docker tag nginx:v2 localhost:5000/nginx:pushone
  • 推送Docker镜像到指定仓库
    docker push localhost:5000/nginx:pushone
  • 查看镜像仓库包含的镜像 curl http://localhost:5000/v2/_catalog

软件测试学习笔记丨构建自己定制化的Nginx并推送_nginx_06

4. 从本地仓库拉取定制好的 Nginx 镜像,启动该 Nginx 访问并截图 。

  • 拉取本地仓库镜像
root@VM-16-5-ubuntu:~# docker pull localhost:5000/nginx:pushone
pushone: Pulling from nginx
Digest: sha256:848b3d96f54dacb67704742e4f067dad6976e57d1f203100ab9b415ec0e076f3
Status: Image is up to date for localhost:5000/nginx:pushone
localhost:5000/nginx:pushone
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 查看镜像
root@VM-16-5-ubuntu:~# docker images
REPOSITORY                  TAG       IMAGE ID       CREATED         SIZE
localhost:5000/nginx        pushone   90002c293a6e   3 hours ago     187MB
  • 1.
  • 2.
  • 3.
  • 启动镜像
  • 软件测试学习笔记丨构建自己定制化的Nginx并推送_docker_07

  • 访问nginx
  • 软件测试学习笔记丨构建自己定制化的Nginx并推送_软件测试_08