我希望Docker for Mac在启动时启动,而不是在登录时启动。我该怎么做呢?我想创建一个LaunchDaemon,我只是不知道该启动什么程序。
我看到的所有例子似乎都是使用docker-machine
来定义虚拟机的,但是现在的文档显示,如果你想使用安装Docker时创建的默认虚拟机,docker-machine
现在不是最佳选择,因为Docker for Mac并不使用docker-machine
来创建虚拟机。
原因是我想在引导时启动Docker来运行Jenkins和Nexus容器,因为服务器将用作CI服务器。Docker GUI具有登录时启动的首选选项,这与启动时不是一回事。
我在运行OSX塞拉。
发布于 2017-03-07 07:15:41
TL;DR将Docker for Mac作为独立服务运行是不支持的。
相反,可以通过创建普通VM或使用docker-machine
在VirtualBox VM中运行Docker。Then set the Virtualbox VM up to run at boot
尝试使用Docker for Mac进行设置
Docker for Mac应用程序创建一个launchd服务:
○→ launchctl list | grep -i docker
- 0 com.docker.helper
78105 0 com.docker.docker.52512
该服务具有以下详细信息:
○→ launchctl list com.docker.docker.52512
{
"LimitLoadToSessionType" = "Aqua";
"Label" = "com.docker.docker.52512";
"TimeOut" = 30;
"OnDemand" = true;
"LastExitStatus" = 0;
"PID" = 78105;
"Program" = "/Applications/Docker.app/Contents/MacOS/Docker";
"ProgramArguments" = (
"/Applications/Docker.app/Contents/MacOS/Docker";
);
"PerJobMachServices" = {
"com.apple.tsm.portname" = mach-port-object;
"com.apple.CFPasteboardClient" = mach-port-object;
"com.apple.coredrag" = mach-port-object;
"com.apple.axserver" = mach-port-object;
};
};
并具有以下进程树:
○→ pstree -p 78105
-+= 00001 root /sbin/launchd
\-+= 78105 matt /Applications/Docker.app/Contents/MacOS/Docker
\-+= 78118 matt /Applications/Docker.app/Contents/MacOS/com.docker.osx.hyperkit.linux -watchdog fd:0 -max-restarts 5 -restart-seconds 30
|--- 78119 matt /Applications/Docker.app/Contents/MacOS/com.docker.osx.hyperkit.linux -watchdog fd:0 -max-restarts 5 -restart-seconds 30
|--= 78120 matt com.docker.db --url fd://3 --git /Users/matt/Library/Containers/com.docker.docker/Data/database
|--= 78121 matt com.docker.osxfs --address fd:3 --connect /Users/matt/Library/Containers/com.docker.docker/Data/@connect --control fd:4 --volume-control
|--= 78122 matt com.docker.slirp --db /Users/matt/Library/Containers/com.docker.docker/Data/s40 --ethernet fd:3 --port fd:4 --introspection fd:5 --diagn
|-+= 78123 matt com.docker.osx.hyperkit.linux
| \--- 78125 matt /Applications/Docker.app/Contents/MacOS/com.docker.osx.hyperkit.linux
\-+= 78124 matt com.docker.driver.amd64-linux -db /Users/matt/Library/Containers/com.docker.docker/Data/s40 -osxfs-volume /Users/matt/Library/Containers
|--- 78126 matt /Applications/Docker.app/Contents/MacOS/com.docker.driver.amd64-linux -db /Users/matt/Library/Containers/com.docker.docker/Data/s40 -o
\--- 78130 matt /Applications/Docker.app/Contents/MacOS/com.docker.hyperkit -A -m 2048M -c 3 -u -s 0:0,hostbridge -s 31,lpc -s 2:0,virtio-vpnkit,uuid=
第一个问题是/Applications/Docker.app/Contents/MacOS/Docker
是位于您的托盘而不是VM中的图形用户界面应用程序,因此在引导时将很难运行。第一个后代/Applications/Docker.app/Contents/MacOS/com.docker.osx.hyperkit.linux
看起来更像是管理VM的东西,所以我们将从这里开始。
获取hyperkit进程的完整命令
○→ ps -fp 78105
UID PID PPID C STIME TTY TIME CMD
501 78105 82644 0 2:08am ?? 0:00.03 /Applications/Docker.app/Contents/MacOS/com.docker.osx.hyperkit.linux -watchdog fd:0 -max-restarts 5 -restart-seconds 30
获取进程的工作目录
○→ sudo lsof -p 78105 | grep cwd
com.docke 78105 matt cwd DIR 1,4 748 63186601 /Users/matt/Library/Containers/com.docker.docker/Data
创建一个包含详细信息的launchd plist文件/Library/LaunchDaemons/com.you.docker.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.you.docker</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/Docker.app/Contents/MacOS/com.docker.osx.hyperkit.linux</string>
<string>-watchdog</string>
<string>fd:0</string>
<string>-max-restarts</string>
<string>5</string>
<string>-restart-seconds</string>
<string>30</string>
</array>
<key>UserName</key>
<string>youruser</string>
<key>WorkingDirectory</key>
<string>/Users/youruser/Library/Containers/com.docker.docker/Data</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
你可以用它加载
sudo launchctl load -w /Library/LaunchDaemons/com.you.docker.plist
然后..。没什么。检查日志
○→ tail /var/log/system.log
Mar 7 02:23:26 mac Docker[87728]: Acquired task manager lock
Mar 7 02:23:26 mac Docker[87728]: Maximum number of file descriptors is 10240
Mar 7 02:23:26 mac Docker[87728]: Failed to read watchdog handshake
Mar 7 02:23:26 mac com.apple.xpc.launchd[1] (com.you.docker[87728]): Service exited with abnormal code: 1
您会注意到,我们正在运行的命令指定了一个选项-watchdog fd:0
,它将是hyperkit进程的stdin
,因此可能缺少一些东西。
如果我再次正常运行Docker,并查看在hyperkit进程工作时FD 0是什么
○→ sudo lsof -p 88360
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.docke 88360 matt 0 PIPE 0xff80ce577ca2ed91 16384 ->0xff80ce5776aa8d51
然后查看整个系统中的PIPE 0xff80ce577ca2ed91
,您将看到主Docker进程为许多进程打开了管道。
○→ sudo lsof | grep 0xff80ce577ca2ed91
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Docker 88349 matt 13 PIPE 0xff80ce5776aa8d51 16384 ->0xff80ce577ca2ed91
com.docke 88360 matt 0 PIPE 0xff80ce577ca2ed91 16384 ->0xff80ce5776aa8d51
com.docke 88362 matt 0 PIPE 0xff80ce577ca2ed91 16384 ->0xff80ce5776aa8d51
com.docke 88363 matt 0 PIPE 0xff80ce577ca2ed91 16384 ->0xff80ce5776aa8d51
com.docke 88364 matt 0 PIPE 0xff80ce577ca2ed91 16384 ->0xff80ce5776aa8d51
com.docke 88365 matt 0 PIPE 0xff80ce577ca2ed91 16384 ->0xff80ce5776aa8d51
com.docke 88366 matt 0 PIPE 0xff80ce577ca2ed91 16384 ->0xff80ce5776aa8d51
尝试在不使用-watchdog fd:0
选项的情况下再次加载服务会导致相同的错误。
因此,看起来主要的Docker应用程序执行了一些运行虚拟机所需的设置。我还没能找到watchdog
选项的源代码,所以不确定它想要什么。
可能会在https://github.com/docker/for-mac上提出问题或功能请求,以从应用程序获取运行VM standalone的详细信息。
https://stackoverflow.com/questions/42637339
复制相似问题