创建好私有仓库之后,就可以使用 docker tag 来标记一个镜像,然后推送它到仓库。例如私有仓库地址为 127.0.0.1:5000。先在本机查看已有的镜像。
1 2 3
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE xueyongshan/python-demo latest 97b87f915673 2 days ago 60.3MB
使用 docker tag 将 xueyongshan/python-demo 这个镜像标记为 127.0.0.1:5000/python:v1。 格式为 docker tag IMAGE[:TAG] [REGISTRY_HOST[:REGISTRY_PORT]/]REPOSITORY[:TAG]
1 2 3 4 5
$ docker tag xueyongshan/python-demo:latest 127.0.0.1:5000/python:v1 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE 127.0.0.1:5000/python v1 97b87f915673 2 days ago 60.3MB xueyongshan/python-demo latest 97b87f915673 2 days ago 60.3MB
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [11:12:47] $ docker rmi 127.0.0.1:5000/python:v1 Untagged: 127.0.0.1:5000/python:v1 Untagged: 127.0.0.1:5000/python@sha256:165e3ef140f7ac367897345d058d3bab24455b19ec7afb0a1ca72a206b43e3f6
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [11:12:53] $ docker pull 127.0.0.1:5000/python:v1 v1: Pulling from python Digest: sha256:165e3ef140f7ac367897345d058d3bab24455b19ec7afb0a1ca72a206b43e3f6 Status: Downloaded newer image for 127.0.0.1:5000/python:v1 127.0.0.1:5000/python:v1
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [11:13:02] $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE 127.0.0.1:5000/python v1 97b87f915673 2 days ago 60.3MB xueyongshan/python-demo latest 97b87f915673 2 days ago 60.3MB
# 1、删除镜像 docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 479bdf321954 registry "/entrypoint.sh /etc…" 7 minutes ago Up 7 minutes 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp registry
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:02:42] $ docker rm -f registry registry
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:02:57] $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 2、启动容器并挂载本地目录 # root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:02:59] $ docker run -d -p 5000:5000 -v $(pwd)/registry:/var/lib/registry registry 2a175bf9e3c7de68d19541ab845c0c1be87acf5b2a11253f4dfddb6e8a73f317
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:03:15] $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2a175bf9e3c7 registry "/entrypoint.sh /etc…" 8 seconds ago Up 3 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp clever_lamarr
# 3、提交镜像 # root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:03:19] $ docker push 127.0.0.1:5000/python:v1 The push refers to repository [127.0.0.1:5000/python] 8c84e798e095: Pushed a4206afdb0ad: Pushed be6b216728ff: Pushed b9a7a7381abe: Pushed 2306fb7a5a47: Pushed 6666686122fd: Pushed 994393dc58e7: Pushed v1: digest: sha256:165e3ef140f7ac367897345d058d3bab24455b19ec7afb0a1ca72a206b43e3f6 size: 1786
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:03:56] $ ls Dockerfile main.py registry # 这里会出现容器中存放镜像的文件夹
# 4、删除容器和镜像 # root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:07:13] $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2a175bf9e3c7 registry "/entrypoint.sh /etc…" 4 minutes ago Up 4 minutes 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp clever_lamarr
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:07:19] $ docker rm -f 2a17 2a17
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:07:42] $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE 127.0.0.1:5000/python v1 97b87f915673 2 days ago 60.3MB xueyongshan/python-demo latest 97b87f915673 2 days ago 60.3MB
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:07:44] $ docker rmi 127.0.0.1:5000/python:v1 Untagged: 127.0.0.1:5000/python:v1 Untagged: 127.0.0.1:5000/python@sha256:165e3ef140f7ac367897345d058d3bab24455b19ec7afb0a1ca72a206b43e3f6
# 5、重新启动容器并拉取镜像 # root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:07:50] $ docker run -d -p 5000:5000 -v $(pwd)/registry:/var/lib/registry registry ff808f4369c83860bdadeb419539d714449817703f170ffb287e34a79edb1e53
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:08:55] $ docker pull 127.0.0.1:5000/python:v1 v1: Pulling from python Digest: sha256:165e3ef140f7ac367897345d058d3bab24455b19ec7afb0a1ca72a206b43e3f6 Status: Downloaded newer image for 127.0.0.1:5000/python:v1 127.0.0.1:5000/python:v1
# 6、查看镜像 # root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:09:03] C:1 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE 127.0.0.1:5000/python v1 97b87f915673 2 days ago 60.3MB xueyongshan/python-demo latest 97b87f915673 2 days ago 60.3MB
# root @ james in /mnt/e/phpStudy/PHPTutorial/WWW/larelastic/docker-python [12:09:05] $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ff808f4369c8 registry "/entrypoint.sh /etc…" 16 seconds ago Up 13 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp loving_moore