Docker 官方维护了一个Docker Hub公共仓库 ,其中已经包括了数量超过 15,000 的镜像。日常大部分需求都可以通过在 Docker Hub 中直接下载镜像来实现,但是有时需要根据自己的需要传自己制作的镜像上去,以供使用。
以下为如何把镜像上传到DockerHub操作过程:
1 DockerHub账号
1.1 注册账号
首先去https://hub.docker.com注册一个hub的帐号;通过执行 docker login 命令交互式的输入用户名及密码来完成在命令行界面登录 Docker Hub。
说明:hub.docker.com有时国内连的会比较慢。
1.2 docker login
[root@centos64-master ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: XXX
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@centos64-master ~]#
1.3 docker logout
通过 docker logout 退出登录。
[root@centos64-master ~]# docker logout
Removing login credentials for https://index.docker.io/v1/
创建后在dockers服务器上使用docker login进行登陆,登陆后即可进行仓库的上传下载动作。
1.4 创建仓库Repositories
在hub.docker.com的Repositories进行Create Repository,例如:
https://hub.docker.com/repository/create?namespace=XXX
Create Repository创建完成
可以看到推送命令:docker push XXX/jmeter:tagname
2 制作docker image
2.1 制作镜像/build image
参考:https://www.cnblogs.com/majestyking/p/10745264.html
做一个简单的包含jdk、Jmeter的docker镜像,jmeter工具包需要自行下载:apache-jmeter-5.4.1.tgz。
##Dockerfile的内容:
FROM java:8
ENV http_proxy ""
ENV https_proxy ""
RUN mkdir /jmeterdocker
RUN mkdir -p /jmeterdocker/test
RUN mkdir -p /jmeterdocker/test/input/jmx
RUN mkdir -p /jmeterdocker/test/input/testdata
RUN mkdir -p /jmeterdocker/test/report/html
RUN mkdir -p /jmeterdocker/test/report/jtl
RUN mkdir -p /jmeterdocker/test/report/outputdata
RUN chmod -R 777 /jmeterdocker
ENV JMETER_VERSION=5.4.1
ENV JMETER_HOME=/jmeterdocker/apache-jmeter-${JMETER_VERSION}
ENV JMETER_PATH=${JMETER_HOME}/bin:${PATH}
ENV PATH=${JMETER_HOME}/bin:${PATH}
COPY apache-jmeter-5.4.1.tgz /jmeterdocker
RUN cd /jmeterdocker \
? ? && tar xvf apache-jmeter-5.4.1.tgz \
? ? && rm apache-jmeter-5.4.1.tgz
##制作镜像命令:
docker build -t jmeterdocker:5.4.1 .
##创建的过程操作:
[root@centos64-master jmeterDocker]# docker build -t jmeterdocker:5.4.1 .
...
apache-jmeter-5.4.1/docs/api/org/apache/log/package-frame.html
apache-jmeter-5.4.1/docs/api/org/apache/log/package-summary.html
apache-jmeter-5.4.1/docs/api/org/apache/log/package-tree.html
Removing intermediate container 670509d604b6
?---> 0f7b46e5322f
Successfully built 0f7b46e5322f
Successfully tagged a007zheng/jmeterdocker:5.4.1
##创建完成以后查询:
[root@centos64-master jmeterDocker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
XXX/jmeterdocker 5.4.1 0f7b46e5322f 29 minutes ago 843MB
2.2 推送镜像/push image
将制作好的镜像 push 到docker hub中,?命令:docker push XXX/jmeterdocker:5.4.1??这个5.4.1其实是一个tag name 会在dcoker?hub的Tags那里显示。
至此镜像推送完成。
2.3 下载镜像/pull image
[root@centos64-master jmeterDocker]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: XXX
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@centos64-master jmeterDocker]# docker push a007zheng/jmeterdocker:5.4.1
The push refers to repository [docker.io/a007zheng/jmeterdocker]
dc7d352b8cfb: Pushed
850aeeb0b696: Pushed
40ba041f31ee: Pushed
58597665b839: Pushed
68b7bf0a8f12: Pushed
cd2401e787ba: Pushed
a5d717d9514a: Pushed
db64250b00fe: Pushed
49e354abf869: Pushed
dd0d548171f1: Pushed
35c20f26d188: Mounted from library/java
c3fe59dd9556: Mounted from library/java
6ed1a81ba5b6: Mounted from library/java
a3483ce177ce: Mounted from library/java
ce6c8756685b: Mounted from library/java
30339f20ced0: Mounted from library/java
0eb22bfb707d: Mounted from library/java
a2ae92ffcd29: Mounted from library/java
5.4.1: digest: sha256:e7727e818c0a67a030ad4a88707827de7c37e56c673b5a3f6ced5848639dadaf size: 4080
[root@centos64-master jmeterDocker]#
##拉去镜像: docker pull XXX/jmeterdocker:5.4.1
[root@centos64-master jmeterDocker]# docker pull xxx/jmeterdocker:5.4.1
5.4.1: Pulling from xxx/jmeterdocker
5040bd298390: Already exists?
fce5728aad85: Already exists?
76610ec20bf5: Already exists?
60170fec2151: Already exists?
e98f73de8f0d: Already exists?
11f7af24ed9c: Already exists?
49e2d6393f32: Already exists?
bb9cdec9c7f3: Already exists?
c9004c093fe0: Pull complete?
38bb535cbdb4: Pull complete?
53d5841b3779: Pull complete?
262d1c454d4d: Pull complete?
1eca5f822fbf: Pull complete?
18c97faa0329: Pull complete?
1447061899ac: Pull complete?
6365eea3d197: Pull complete?
9f3230d55558: Pull complete?
e297f63ae8de: Pull complete?
Digest: sha256:e7727e818c0a67a030ad4a88707827de7c37e56c673b5a3f6ced5848639dadaf
Status: Downloaded newer image for xxx/jmeterdocker:5.4.1
docker.io/xxx/jmeterdocker:5.4.1
[root@centos64-master jmeterDocker]# docker images
REPOSITORY ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TAG ? ? ? ?IMAGE ID ? ? ? CREATED ? ? ? ? ?SIZE
xxx/jmeterdocker ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?5.4.1 ? ? ?0f7b46e5322f ? 29 minutes ago ? 843MB
3 相关
https://hub.docker.com/
|