docker常用命令
Docker pull/push image测试
制作要push到registry的镜像
#查看本地已有镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2 cd57aad0bd45 3 days ago 224.5 MB
nginx 1.9 813e3731b203 3 weeks ago 133.9 MB
#为本地镜像打标签
$ docker tag registry:2 docker-registry.com/registry:2
$ docker tag nginx:1.9 docker-registry.com/nginx:1.9
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2 cd57aad0bd45 3 days ago 224.5 MB
docker-registry.com/registry 2 cd57aad0bd45 3 days ago 224.5 MB
nginx 1.9 813e3731b203 3 weeks ago 133.9 MB
docker-registry.com/nginx 1.9 813e3731b203 3 weeks ago 133.9 MB
push测试
#不登陆直接push镜像到registry,会提示失败
[root@PRO-REGISTRY-220 ~]# docker push docker-registry.com/registry
The push refers to a repository [docker-registry.com/registry] (len: 1)
cd57aad0bd45: Image push failed
cd57aad0bd45: Buffering to Disk
Please login prior to push:
Username:
Error response from daemon: no successful auth challenge for https://docker-registry.com/v2/ - errors: [basic auth attempt to https://docker-registry.com/v2/ realm "registry.localhost" failed with status: 401 Unauthorized]
#登陆后,再试
$docker login https://docker-registry.com
Username: docker
Password:
Email:
WARNING: login credentials saved in /root/.docker/config.json
Login Succeeded
#可以push 镜像到registry
$ docker push docker-registry.com/registry
The push refers to a repository [docker-registry.com/registry] (len: 1)
cd57aad0bd45: Image already exists
b3c39a7768ea: Image successfully pushed
4725a48b84d4: Image successfully pushed
7b4078296418: Image successfully pushed
7bd663e30ad0: Image successfully pushed
28864e830e4d: Image successfully pushed
7bd2d56d8449: Image successfully pushed
af88597ec24b: Image successfully pushed
b2ae0a712b39: Image successfully pushed
02e5bca4149b: Image successfully pushed
895b070402bd: Image successfully pushed
Digest: sha256:92835b3e54c05b90e416a309d37ca02669eb5e78e14a0f5ccf44b90d4c21ed4c
搜索镜像
curl https://docker:123456@docker-registry.com/v2/_catalog
{"repositories":["registry"]}
curl https://docker:123456@docker-registry.com/v2/nginx/tags/list
{"name":"registry","tags":["2"]}
pull测试
$ docker logout https://docker-registry.com
Remove login credentials for https://docker-registry.com
#不登陆registry直接pull镜像也会失败
$ docker pull docker-registry.com/registry:2
Pulling repository docker-registry.com/registry
Error: image registry:2 not found
#登陆后再测试
$ docker login https://docker-registry.com
Username: docker
Password:
Email:
WARNING: login credentials saved in /root/.docker/config.json
Login Succeeded
#登陆后可以pull
$ docker pull docker-registry.com/registry:2
1.9: Pulling from dev-docker-registry.com/registry
6d1ae97ee388: Already exists
8b9a99209d5c: Already exists
3244b9987276: Already exists
50e5c9c52d5d: Already exists
146400830f31: Already exists
b412cc1cde63: Already exists
7fe375038652: Already exists
c43f11a030f9: Already exists
152297b50994: Already exists
01e808fa2993: Already exists
813e3731b203: Already exists
Digest: sha256:af688d675460d336259d60824cd3992e3d820a90b4f31015ef49dc234a00adc3
Status: Downloaded newer image for docker-registry.com/registry:2
六、CentOS 7安装Docker及常用命令
yum install docker #安装docker
sudo systemctl daemon-reload #启动docker-daemon
sudo systemctl restart docker #重启启动docker
systemctl start docker.service #启动docker
systemctl enable docker.service #docker开机启动
docker -v #查看docker版本
docker info #查看docker具体信息
docker pull centos #下载centos image
docker images #显示已有image
docker rmi imageid #删除image
sudo usermod -a -G docker wisely #非root用户使用
docker run -i -t centos /bin/bash #启动系统
docker stop $(docker ps -a -q) #停止所有容器
docker rm $(docker ps -a -q) #删除所有container
docker rmi $(docker images -q) #删除所有image
docker inspect container_name #查看容器信息
docker inspect container_name | grep IPAddress #查看当前容器ip地地址
docker attach --sig-proxy=false 304f5db405ec (按control +c 退出不停止容器)
Dockerfile构建Tomcat
详见地址:http://wp.lu1688.cn/2017/05/08/docker-利用dockerfile来搭建tomcat服务/
Docker-容器的操作
详见地址:http://wp.lu1688.cn/2017/05/08/docker-容器的操作/
常用docker命令,及一些坑
详见地址:http://wp.lu1688.cn/2017/05/08/常用docker命令,及一些坑/