1.在本地创建一个 Dockerfile
FROM ubuntu:latest
RUN apt-get update && apt-get install -y curl
CMD ["curl", "https://www.baidu.com"]
2.在本地构建 Docker 镜像
在创建本地docker镜像的时候[TAG] .和[TAG] /PATH/TO 需要注意dockerfile文件的文件命名需要固定格式{Dockerfile}
docker build -t [DOCKERHUB_USERNAME]/[IMAGE_NAME]:[TAG] .
其中 [DOCKERHUB_USERNAME] 是您的 Docker Hub 用户名,[IMAGE_NAME] 是您要创建的镜像名称,[TAG] 是您要使用的镜像标签。请注意,上面命令中的最后一个点表示将当前目录作为构建上下文。
[root@wide Dockerfile]# docker build -t widesky41/imagesky:0.1 .
[+] Building 2.0s (7/7)FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 207B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:latest 2.0s
=> [auth] library/ubuntu:pull token for registry-1.docker.io 0.0s
=> [1/2] FROM docker.io/library/ubuntu:latest@sha256:67211c14fa74f070d27cc59d69a7fa9aeff8e28ea118ef3babc295a0428a6d21 0.0s
=> CACHED [2/2] RUN apt-get update && apt-get install -y curl 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:7f0e5b0487416950a45faa1c20463da3b34ad0698f87f58436f5e68258ca8275 0.0s
=> => naming to docker.io/widesky41/imagesky:0.1
3.登录和注销Docker Hub
[root@wide Dockerfile]# docker logout
Removing login credentials for <https://index.docker.io/v1/>
[root@wide Dockerfile]# 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: widesky41
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
4.将本地镜像推送到 Docker Hub
接下来,使用以下命令将本地构建的镜像推送到 Docker Hub:
docker push [DOCKERHUB_USERNAME]/[IMAGE_NAME]:[TAG]
其中 [DOCKERHUB_USERNAME] 是您的 Docker Hub 用户名,[IMAGE_NAME] 是您要推送的镜像名称,[TAG] 是您要使用的镜像标签。例如:
[root@wide Dockerfile]# docker push widesky41/imagesky:0.1
The push refers to repository [docker.io/widesky41/imagesky]
fa9f6ebf8d7f: Pushed
b93c1bd012ab: Pushed
0.1: digest: sha256:f67a0ef55f716920be7ef10d908fad0dd856cc139ccf47a07ab53a0e8442b733 size: 741
var code = "c930935e-0f39-4bb2-9181-0c3357759a6f"