0.前提是注册了dockerhub账号
1.登陆dockerhub
docker login --help #查看登陆帮助,看看登陆参数格式
eg:
[root@hc /]# docker login --help
Usage: docker login [OPTIONS] [SERVER]
Log in to a Docker registry.
If no server is specified, the default is defined by the daemon.
Options:
-p, --password string Password
--password-stdin Take the password from stdin
-u, --username string Username
1.1 登陆dockerhub
docker login -u huangchongdocker
#随后输入正确的密码
eg:
[root@hc /]# docker login -u huangchongdocker
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
2.提交镜像
docker images # 查看所有镜像
docker tag 镜像id 镜像名:tag # 选做,给镜像添加tag版本信息或者改镜像名
docker push docker-cmd-test:1.0.0 #发布镜像到dockerhub
实战:
[root@hc /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dockerfile-entrypoint-test latest 46808b7f9089 10 days ago 209MB
docker-cmd-test latest 21dafa26e85f 10 days ago 209MB
mycentos 1.0 7183d35483d8 13 days ago 282MB
nginx latest f0b8a9a54136 3 weeks ago 133MB
[root@hc /]# docker tag 21dafa26e85f docker-cmd-test:1.0.0
[root@hc /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dockerfile-entrypoint-test latest 46808b7f9089 10 days ago 209MB
docker-cmd-test 1.0.0 21dafa26e85f 10 days ago 209MB
docker-cmd-test latest 21dafa26e85f 10 days ago 209MB
mycentos 1.0 7183d35483d8 13 days ago 282MB
nginx latest f0b8a9a54136 3 weeks ago 133MB
mysql 5.7 2c9028880e58 3 weeks ago 447MB