原文:http://www.javashuo.com/article/p-qwewtcoj-mz.htmlhtml
$docker run -i -t <image_name/continar_id> /bin/bash
$docker run -d -it image_name
ps:这里的 image_name 包含了tag:hello.demo.kdemo:v1.0docker
docker attach <id、container_name>
docker exec -t -i <id/container_name> /bin/bash
ps:docker exec是如此的有用,以致于咱们一般是将其封装为一个脚本,放到全局可调用的地方,好比,能够写成一个indocker.sh:bash
$cat indocker.sh docker exec -t -i $1 /bin/bash # 查看须要附着的容器id $docker ps | less -S CONTAINER ID IMAGE 9cf7b563f689 hello.demo.kdemo:v160525.202747 $./indocker.sh 9cf7b563f689
docker logs <id/container_name>
docker logs -f <id/container_name> (相似 tail -f) (带上时间戳-t)
$docker ps
$docker ps | less -S
$docker ps -a
$docker ps -l
$docker top Name/ID
$docker inspect <id/container_name>
$docker run image_name apt-get install -y app_name
Note: 在执行apt-get 命令的时候,要带上-y参数。若是不指定-y参数的话,apt-get命令会进入交互模式,须要用户输入命令来进行确认,但在docker环境中是没法响应这种交互的。apt-get 命令执行完毕以后,容器就会中止,但对容器的改动不会丢失。网络
$docker cp Name:/container_path to_path $docker cp ID:/container_path to_path
$docker commit ID new_image_name
Note: image至关于类,container至关于实例,不过能够动态给实例安装新软件,而后把这个container用commit命令固化成一个image。app
$docker rm Name/ID
-f, –force=false; -l, –link=false Remove the specified link and not the underlying container; -v, –volumes=false Remove the volumes associated to the containerless
$docker rm `docker ps -a -q`
$docker stop Name/ID $docker start Name/ID $docker kill Name/ID $docker restart name/ID
$sudo docker images
-a, –all=false Show all images; –no-trunc=false Don’t truncate output; -q, –quiet=false Only show numeric IDsdom
$docker search image_name
$docker pull image_name
$docker rmi image_name
-f, –force=false Force; –no-prune=false Do not delete untagged parentsui
$docker history image_name
$docker push new_image_name
ps:要发布到私有Registry中的镜像,在镜像命名中须要带上Registry的域名(若是非80端口,同时须要带上端口号)好比:spa
$docker push dockerhub.yourdomain.com:443/hello.demo.kdemo:v1.0
$docker pull image_name
$ip a show docker0
$docker inspect -f '{{ .NetworkSettings.IPAddress }}' <id、container_name>
附着到容器内部查看其内部ip:rest
$ip a show eth0
$docker version
$docker info
Ctrl+P+Q
docker cp foo.txt mycontainer:/foo.txt