码迷,mamicode.com
首页 > 系统相关 > 详细

linux--docker学习笔记

时间:2016-09-29 20:31:48      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:

安装
yum install docker-io
yum upgrade device-mapper-libs
service docker start
docker pull centos   //拉取centos镜像, 貌似这个东东在国外 网络很差要等些时间才能下载完

 今天:
 写支付接口文档;
 
c=>linux 核心编程=>linux网络编程=>c++peimer=>efftcive stl 

查看版本:docker -v 
查看帮助信息:docker 
在官方仓库搜寻镜像:docker search centos 
查看本地镜像:docker images 
下载仓库镜像到本地:docker pull centos:latest 
上传本地镜像到仓库:docker push NAME[:TAG] 

将镜像保存为tar文件:docker save -o tar文件 镜像ID/镜像tag 
将tar文件加载为镜像:docker load -i tar文件

修改镜像tag:docker tag 镜像ID 镜像tag 
删除镜像:docker rmi 镜像ID/镜像tag 
制作镜像:docker build -t centos:autosshd - < dockerfile.txt

查看镜像历史:docker history 镜像ID/镜像tag
 
创建容器:docker run -d --name=容器名称 镜像ID/镜像tag 
                     杠d是指后台运行 --name相当于mysql语法中 as 
例如 docker run --name centosrongqi -i -t centos /bin/bash
                          -i:打开容器中的STDIN 
                      -t:为容器分配一个伪tty终端
启动容器:docker start 容器名称/容器ID 

查看容器:docker ps -a  表示运行过哪些容器

 docker commit -m "描述" -a "saymagic" 79c761f627f3 saymagic/ubuntu-nginx:v1
                        -a可以指定用户信息的
rpm -q centos-release
  centos-release-5-4.el5.centos.1 


重启容器:docker restart 容器名称/容器ID

停止容器:docker stop 容器名称/容器ID

删除容器:docker rm 容器名称/容器ID

暂停容器:docker pause 容器名称/容器ID

恢复容器:docker unpause 容器名称/容器ID

执行命令:docker exec -ti 容器名称/容器ID /bin/bash

获取容器日志:docker logs 容器名称/容器ID


对image的操作(search、pull、images、rmi、history
# 检索image
$docker search image_name

# 下载image
$docker pull image_name

# 列出镜像列表; -a, --all=false Show all images; --no-trunc=false Dont 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 Dont truncate output; -q, --quiet=false Only show numeric IDs
$docker history image_name



 启动容器(run)
# 在容器中运行"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


 查看容器(ps)

# 列出当前所有正在运行的container
$docker ps
# 列出所有的container
$docker ps -a
# 列出最近一次启动的container
$docker ps -l


 保存对容器的修改(commit)
# 保存对容器的修改; -a, --author="" Author; -m, --message="" Commit message
$docker commit ID new_image_name



6. 对容器的操作(rm、stop、start、kill、logs、diff、top、cp、restart、attach)
# 删除所有容器
$docker rm `docker ps -a -q`

# 删除单个容器; -f, --force=false; -l, --link=false Remove the specified link and not the underlying container; -v, --volumes=false Remove the volumes associated to the container
$docker rm Name/ID

# 停止、启动、杀死一个容器
$docker stop Name/ID
$docker start Name/ID
$docker kill Name/ID

# 从一个容器中取日志; -f, --follow=false Follow log output; -t, --timestamps=false Show timestamps
$docker logs Name/ID

# 列出一个容器里面被改变的文件或者目录,list列表会显示出三种事件,A 增加的,D 删除的,C 被改变的
$docker diff Name/ID

# 显示一个运行的容器里面的进程信息
$docker top Name/ID

# 从容器里面拷贝文件/目录到本地一个路径
$docker cp Name:/container_path to_path
$docker cp ID:/container_path to_path

# 重启一个正在运行的容器; -t, --time=10 Number of seconds to try to stop for before killing the container, Default=10
$docker restart Name/ID

# 附加到一个运行的容器上面; --no-stdin=false Do not attach stdin; --sig-proxy=true Proxify all received signal to the process
$docker attach ID
Note: attach命令允许你查看或者影响一个运行的容器。你可以在同一时间attach同一个容器。你也可以从一个容器中脱离出来,是从CTRL-C。





7. 保存和加载镜像(save、load)
当需要把一台机器上的镜像迁移到另一台机器的时候,需要保存镜像与加载镜像。

# 保存镜像到一个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

8、 登录registry server(login)
# 登陆registry server; -e, --email="" Email; -p, --password="" Password; -u, --username="" Username
$docker login




9. 发布image(push)
# 发布docker镜像
$docker push new_image_name

10.  根据Dockerfile 构建出一个容器
#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_pat












其中<>阔起来的参数为必选,[]阔起来为可选

docker version 查看docker的版本号,包括客户端、服务端、依赖的Go等
docker info 查看系统(docker)层面信息,包括管理的images, containers数等
docker search <image> 在docker index中搜索image
docker pull <image> 从docker registry server 中下拉image
docker push <image|repository> 推送一个image或repository到registry
docker push <image|repository>:TAG 同上,指定tag
docker inspect <image|container> 查看image或container的底层信息
docker images TODO filter out the intermediate image layers (intermediate image layers 是什么)
docker images -a 列出所有的images
docker ps 默认显示正在运行中的container
docker ps -l 显示最后一次创建的container,包括未运行的
docker ps -a 显示所有的container,包括未运行的
docker logs <container> 查看container的日志,也就是执行命令的一些输出
docker rm <container...> 删除一个或多个container
docker rm `docker ps -a -q` 删除所有的container
docker ps -a -q | xargs docker rm 同上, 删除所有的container
docker rmi <image...> 删除一个或多个image
docker start/stop/restart <container> 开启/停止/重启container
docker start -i <container> 启动一个container并进入交互模式
docker attach <container> attach一个运行中的container
docker run <image> <command> 使用image创建container并执行相应命令,然后停止
docker run -i -t <image> /bin/bash 使用image创建container并进入交互模式, login shell是/bin/bash
docker run -i -t -p <host_port:contain_port> 将container的端口映射到宿主机的端口
  例如 docker run -d -p 81:80 centos-nginx /usr/local/openresty/nginx/sbin/nginx
        docker run -d -p 192.168.9.11:2201:22 nginx/centos /usr/sbin/sshd -D
        用ssh root@192.168.9.11 -p 2201 连接容器,提示:
        Connection to 192.168.1.205 closed.(此问题还未解决!!!)
          
  
docker commit <container> [repo:tag] 将一个container固化为一个新的image,后面的repo:tag可选
docker build <path> 寻找path路径下名为的Dockerfile的配置文件,使用此配置生成新的image
docker build -t repo[:tag] 同上,可以指定repo和可选的tag
docker build - < <dockerfile> 使用指定的dockerfile配置文件,docker以stdin方式获取内容,使用此配置生成新的image
docker port <container> <container port> 查看本地哪个端口映射到container的指定端口,其实用docker ps 也可以看到

 

linux--docker学习笔记

标签:

原文地址:http://www.cnblogs.com/sixiong/p/5920861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!