docker学习

docker 入门

运行docker 自带的hello world

docker run hello-world

运行容器

docker -i -t ubuntu /usr/bin/bash

容器命名

docker run --name bob_the_brother -it ubuntu /usr/bin/bash

重新启动已经停止的容器

//通过命名
docker start bob_the_brother
//通过id
docker start <id>

进入已经运行的容器

docker attach bob_the_brother

创建守护容器

docker run -d <container> -name daemon_dave

获取容器日志

docker logs daemon_dave
# -f 循环读取
# -t 时间戳

容器日志驱动

docker run --log-driver="syslog" --name daemon_dave -d ubuntu /usr/bin/bash

## 查看守护式容器的进程
```shell
docker top daemon_dave

查看容器的统计状态信息

docker stats daemon_dave

在容器内部运行任务

# 容器内部运行后台
docker exec -d daemon_dave touch /etc/new_config_file
# 容器内部运行交互任务
docker exec -t -i daemon_dave /bin/bash

停止守护容器

docker stop daemon_dave
docker stop <id>

自动重启容器

docker run --restart=always --name daemon_dave -d ubuntu /bin/bash
# 指定重启次数
--restart=on-failure:5

深入容器

查看容器象析信息

docker inspect daemon_dave

删除容器

docker rm <id>
# 删除所有容器
docker rm `docker ps -a -q`

docker 镜像

列出镜像

docker images

拉取镜像

docker pull ubuntu:12.04
# 查看指定镜像
docker pull images ubuntu

在docker hub上查找镜像

docker search puppet

提交定制容器

docker commit <id> 镜像仓库/镜像名
-m 提交信息
-a 作者信息

使用Dockerfile构建

原文地址:https://www.cnblogs.com/zhouyu0-0/p/13945810.html