docker cmd line
$ ID=$(sudo docker run -d ubuntu /usr/bin/top -b) $ sudo docker attach $ID
在容器中运行top命令。如果attach 的时候就能看到top的是输出。
$ sudo docker stop $ID 就能结束这个容器。
docker build PATH 比如 `.` 会把当前目录的文件送给守护进程。
cp
Copy files/folders from the containers filesystem to the host path. Paths are relative to the root of the filesystem.
Usage: docker cp CONTAINER:PATH HOSTPATH
记录守护进程的事件
Shell 1: Listening for events:
$ sudo docker events
Shell 2: Start and Stop a Container:
$ sudo docker start 4386fb97867d
$ sudo docker stop 4386fb97867d
Shell 1: (Again .. now showing events):
[2013-09-0315:49:26+0200 CEST]4386fb97867d:(from12de384bfb10) start
[2013-09-0315:49:29+0200 CEST]4386fb97867d:(from12de384bfb10)die[2013-09-0315:49:29+0200 CEST]4386fb97867d:(from12de384bfb10) stop
Show events in the past from a specified time:
$ sudo docker events --since 1378216169[2013-09-0315:49:29+0200 CEST]4386fb97867d:(from12de384bfb10)die[2013-09-0315:49:29+0200 CEST]4386fb97867d:(from12de384bfb10) stop
$ sudo docker events --since '2013-09-03'[2013-09-0315:49:26+0200 CEST]4386fb97867d:(from12de384bfb10) start
[2013-09-0315:49:29+0200 CEST]4386fb97867d:(from12de384bfb10)die[2013-09-0315:49:29+0200 CEST]4386fb97867d:(from12de384bfb10) stop
$ sudo docker events --since '2013-09-03 15:49:29 +0200 CEST'[2013-09-0315:49:29+0200 CEST]4386fb97867d:(from12de384bfb10)die[2013-09-0315:49:29+0200 CEST]4386fb97867d:(from12de384bfb10) stop
Docker 和 UFW
Dockers是用桥接的方式管理容器的网络,默认情况下,如果你安装了UFW防火墙,他会过滤掉所有的转发,所以你需要允许UFW转发
sudo nano /etc/default/ufw
----
# Change:
# DEFAULT_FORWARD_POLICY="DROP"
# to
DEFAULT_FORWARD_POLICY="ACCEPT"