标签:
# 查看docker版本 $docker version # 显示docker系统的信息 $docker info
# 检索image $docker search image_name # 下载image $docker pull image_name # 列出镜像列表; -a, --all=false Show all images; --no-trunc=false Don‘t truncate output; -q, --quiet=false Only show numeric IDs $docker images # 删除一个或者多个镜像; -f, --force=false Force; --no-prune=false Do not delete untagged parents $docker rmi image_name # 显示一个镜像的历史; --no-trunc=false Don‘t truncate output; -q, --quiet=false Only show numeric IDs $docker history image_name
docker容器可以理解为在沙盒中运行的进程。这个沙盒包含了该进程运行所必须的资源,包括文件系统、系统类库、shell 环境等等。但这个沙盒默认是不会运行任何程序的。你需要在沙盒中运行一个进程来启动某一个容器。这个进程是该容器的唯一进程,所以当该进程结束的时候,容器也会完全的停止。
# 在容器中运行"echo"命令,输出"hello word" $docker run image_name echo "hello word" # 交互式进入容器中 $docker run -i -t image_name /bin/bash # 在容器中安装新的程序 $docker run image_name apt-get install -y app_name
Note: 在执行apt-get 命令的时候,要带上-y参数。如果不指定-y参数的话,apt-get命令会进入交互模式,需要用户输入命令来进行确认,但在docker环境中是无法响应这种交互的。apt-get 命令执行完毕之后,容器就会停止,但对容器的改动不会丢失。
当需要把一台机器上的镜像迁移到另一台机器的时候,需要保存镜像与加载镜像。
# 保存镜像到一个tar包; -o, --output="" Write to an file $docker save image_name -o file_path # 加载一个tar包格式的镜像; -i, --input="" Read from a tar archive file $docker load -i file_path # 机器a $docker save image_name > /home/save.tar # 使用scp将save.tar拷到机器b上,然后: $docker load < /home/save.tar
# 登陆registry server; -e, --email="" Email; -p, --password="" Password; -u, --username="" Username $docker login
# 发布docker镜像 $docker push new_image_name
#build --no-cache=false Do not use cache when building the image -q, --quiet=false Suppress the verbose output generated by the containers --rm=true Remove intermediate containers after a successful build -t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success $docker build -t image_name Dockerfile_path
标签:
原文地址:http://www.cnblogs.com/wangkuan/p/5425998.html