docker基本操作

1.安装yum源,/etc/yum.repos.d

[docker]
name=doker repo
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever
enabled=1
gpgcheck=0

# yum update

# yum -y install docker-engine

2.服务相关

# service docker restart  重启

# docker version  查看版本

3.镜像相关命令

# docker pull hello-world  获取镜像

# docker run -it ubuntu /bin/bash  运行镜像

# docker  images  查看镜像信息

# docker tag hello-world:latest my-hello-world:my-latest  添加镜像标签

# docker inspect ubuntu  查看镜像详细信息

# docker history hello-world  查看镜像历史信息

# docker search --automated -s 3 nginx  查看镜像,--automated:显示自动创建的,-s:评价值

# docker rmi hello-world  删除镜像

# docker commit -m "add a new file" -a "newbee" 5f2b0214e73c test:0.1  提交一个新镜像,-a:作者,-m:提交信息,repo+tag

# docker save -o hello-world.tar hello-world  存出镜像

# docker load < hello-world.tar  载入镜像

# docker tag hello-world:latest wangmo/my-hello-world:my-latest  push操作:先打个标签,加上用户名

# docker push wangmo/my-hello-world  上传镜像

3.容器相关命令

# docker ps  查看当前运行的容器,-a:查看所有

# docker create -it ubuntu:latest  新建容器

# docker start b09599991380  启动容器

# docker run -it ubuntu /bin/echo "hello"  启动并运行容器,-d:守护态

# docker logs 7f5  查看容器日志

# docker stop 50f  终止容器

# docker attach 50f  进入容器方式1

# docker exec -it 50f /bin/bash  进入容器方式2

# docker rm d76  删除容器

# docker rm `docker ps -a -q`  删除所有容器

# docker export -o test_for_run.tar 50f  导出容器

# cat test_for_run.tar | docker import - test/test:v1.0  导入容器

4.搭建本地私有仓库

# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry  -v:指定路径,-P:随机分配端口号,-p:指定端口,-d:后台运行

http://www.cnblogs.com/xcloudbiz/articles/5500578.html

原文地址:https://www.cnblogs.com/wangmo/p/6761495.html