标签:
$docker run -i -t <image_name/continar_id> /bin/bash
$docker run -d -it image_name
ps:这里的 image_name 包含了tag:hello.demo.kdemo:v1.0
docker attach <id、container_name>
docker exec -t -i <id/container_name> /bin/bash
ps:docker exec是如此的有用,以至于我们通常是将其封装为一个脚本,放到全局可调用的地方,比如,可以写成一个indocker.sh:
$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。
$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 container
$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 IDs
$docker search image_name
$docker pull image_name
$docker rmi image_name
-f, –force=false Force; –no-prune=false Do not delete untagged parents
$docker history image_name
$docker push new_image_name
ps:要发布到私有Registry中的镜像,在镜像命名中需要带上Registry的域名(如果非80端口,同时需要带上端口号)比如:
$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:
$ip a show eth0
$docker version
$docker info
标签:
原文地址:http://www.cnblogs.com/Leo_wl/p/5539056.html