了解docker过程中的一些简单笔记。
基本概念
image & container
官方解释如下:
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.
类比一下,有些像类与对象的关系,或者程序与进程的关系
volume
Docker containers are a lot more scalable and modular once they have the links in place that allow them to share data. How these links are created and arranged depends upon the arranger, who will choose either to create a file-system data volume or a dedicated data volume container.
This post works thorough these two common choices; data volumes and data volume containers. With consideration of the commands involved in backing up, restoring, and migrating said data volumes.
根据上面的描述,可以了解到,volume指的是用于保存数据的目录,可以在host上,也可以在container中。
基本使用
下载一个image
$ docker pull xxx
以daemon形式启动image,并创建一个container来运行(以jenkins为例)
$ docker run --name myjenkins -p 8080:8080 -p 50000:50000 jenkins
进入docker容器
$ docker exec -it myjenkins /bin/bash
更多其他操作形式,参考如何进入docker容器
查看当前已经启动的container
$ docker ps
将指定目录共享给docker容器(mac)
// ~/Desktop为host上的目录,/Desktop为container中的目录
$ docker run -it -v ~/Desktop:/Desktop ${image_name} bash
关闭运行中的container
$ docker stop ${container_id}