[关闭]
@SailorXiao 2016-08-25T16:11:05.000000Z 字数 2326 阅读 1709

docker学习笔记一 安装和配置

docker 容器 虚拟化


技术资料

docker中文官网:http://www.docker.org.cn/
中文入门课程:http://www.docker.org.cn/book/docker.html
docker学习笔记:http://www.open-open.com/lib/view/open1423703640748.html
深入浅出docker:http://www.infoq.com/cn/articles/docker-core-technology-preview

安装

参考:http://www.docker.org.cn/book/install/install-docker-on-rhel-29.html

配置

在centos7中,docker的默认配置在/usr/lib/systemd/system/docker.service,可以做一些配置:

- --insecure-registry 127.0.0.1:5000 Docker 1.3版本后,与registry交互默认使用https,配置后表示跟该仓库交互形式为http

使用

docker search --help

Usage: docker search [OPTIONS] TERM

Search the Docker Hub for images

  --automated=false    Only show automated builds
  --help=false         Print usage
  --no-trunc=false     Don't truncate output
  -s, --stars=0        Only displays with at least x stars

如果要搜索非docker hub上的镜像,可以增加仓库地址,比如

pull

docker pull --help  

Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Pull an image or a repository from the registry

  -a, --all-tags=false    Download all tagged images in the repository
  --help=false            Print usage

在下载的时候,可以使用TAG,默认下载的是latest,默认是从docker hub上下载,如果要从docker hub的个人仓库中下载,需要加上个人账号前缀

docker pull sailor/mycentos
从docker hub的sailor用户仓库上下载mycentos镜像

也可以显示指定不从docker hub上下载,比如

docker pull dl.dockerpool.com:5000/centos
表示从dl.dockerpool.com:5000上下载centos镜像

run

docker run --help

Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

  -a, --attach=[]             Attach to STDIN, STDOUT or STDERR
  --add-host=[]               Add a custom host-to-IP mapping (host:ip)
  --blkio-weight=0            Block IO (relative weight), between 10 and 1000
  -c, --cpu-shares=0          CPU shares (relative weight)
  --cpuset-cpus=              CPUs in which to allow execution (0-3, 0,1)
  --cpuset-mems=              MEMs in which to allow execution (0-3, 0,1)
  -d, --detach=false          Run container in background and print container ID
  ...
  ...

docker run参数很多,包括指定容器运行资源(CPU/MEM等),以及一些其它参数,常用:

docker run -t -i centos /bin/bash
-t表示启动一个tty(控制台), -i表示开启stdin输出,/bin/bash表示在镜像中执行/bin/bash命令

commit

当对镜像做了修改后,想重新提交的时候,需要用到commit命令

docker commit --help

Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Create a new image from a container's changes

  -a, --author=       Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change=[]     Apply Dockerfile instruction to the created image
  --help=false        Print usage
  -m, --message=      Commit message
  -p, --pause=true    Pause container during commit

push

参考:http://blog.chinaunix.net/uid-20788636-id-5049772.html

  1. 在docker hub中注册一个账户,比如注册账户为sailor
  2. 在本机进行docker login,需要填写参数:username password email等
  3. 将原来的镜像打标签成 {username}/xxx,比如讲centos镜像通过打标签成 sailor/mycentos
  4. 使用docker push将其发布到docker hub的sailor账户的仓库中
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注