本地用的Docker for Mac,使用official tutorial 进行前期安装工作。安装好后,运行第一个命令docker --version。Docker version 1.12.1,
本地用的Docker for Mac,使用official tutorial 进行前期安装工作。
安装好后,运行第一个命令docker --version。
Docker version 1.12.1, build 6f9534c
官方文档上面一直提到一个Docker Toolbox,是对不满足Docker for Mac的系统配置要求"macOS 10.10.3 Yosemite or newer",则建议安装Docker Toolbox。
- 简单运行起来一个container。
从Docker hub上搜索一个image。
docker search hello-world
从Docker hub上pull一个image。
docker pull hello-world
基于image运行一个container。
docker run hello-world
- 其实用一条命令就可以完成上面的一项:docker run hello-world
运行docker run的时候,docker engine其实做了三个动作:
- 检查本地是否有hello-world的image
- 如果本地没有,从Docker hub下载hello-world的image(不只是Docker hub上)
- 加载image去运行一个container
- 列举出所有container和image
显示所有运行中的container
docker ps
显示所有被创建的container
docker ps -a
显示最近一个被创建的container
docker ps -l
显示本地所有image
docker images
- image和container
Docker Engine provides the core Docker technology that enables images and containers.An image is a filesystem and parameters to use at runtime. It doesn’t have state and never changes. A container is a running instance of an image.
.- 在container下运行命令
docker run ubuntu echo "hello word"
当命令执行完毕时,container即会停止。
docker run -t -i ubuntu /bin/bash
host运行一个container,并且打开一条交互连接。
.-t flag assigns a pseudo-tty or terminal inside the new container.
-i flag allows you to make an interactive connection by grabbing the standard input (STDIN) of the container.
docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"
用后台进程的形式运行命令。
.-d flag runs the container in the background (to daemonize it).
.注意:如果不指定contrainer name,docker将自动生成container name。
- 查看指定container的标准输出信息
docker logs <containerId>[<containerName>]docker logs -f <containerId>[<containerName>] //-f 效果同tail -f
- 停止/启动/删除container
docker stop <containerID>[<containerName>]docker start <containerID>[<containerName>]docker rm <containerID>[<containerName>]