通过远程访问API访问Docker for Mac [英] Accessing Docker for Mac via Remote Access API
问题描述
为了在本地访问守护程序,我使用UNIX套接字 /var/run/docker.sock
,但UNIX套接字无法联网,所以我发现一篇文章解释了如何在Ubuntu上启用Docker Remote Access REST API( http://www.virtuallyghetto.com/2014/07/quick-tip-how-to-enable-docker-remote-api.html )。它解释了我需要如何将 DOCKER_OPTS =' - H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock'
文件 /etc/init/docker.conf
,但是我无法在我的Mac上找到这个文件。
任何帮助或指示将不胜感激,
干杯
p>您需要设置一个 DOCKER_HOST 环境变量:
export DOCKER_HOST =' - H unix: ///var/run/docker.sock -H tcp:// localhost:2376'
你可以在〜/ Library / LaunchAgents /
中在系统启动时创建一个 environment.plist
文件:
<?xml version =1.0encoding =UTF-8?>
<!DOCTYPE plist PUBLIC - // Apple // DTD PLIST 1.0 // ENhttp://www.apple.com/DTDs/PropertyList-1.0.dtd\">
< plist version =1.0>
< dict>
< key> Label< / key>
< string> my.startup< / string>
< key> ProgramArguments< / key>
< array>
< string> sh< / string>
< string> -c< / string>
< string>
launchctl setenv DOCKER_HOST -H unix:///var/run/docker.sock -H tcp:// localhost:2376
< / string>
< / array>
< key> RunAtLoad< / key>
< true />
< / dict>
< / plist>
I've been recently experimenting with Docker and I would like to be able to access Docker from within a container in order to run more containers. As I'm experimenting with the platform, I'm running it locally on my Mac, and I am unsure how I would enable the Docker Daemon to be accessed from inside a container.
In order to access the daemon locally, I use the UNIX socket /var/run/docker.sock
, however UNIX sockets are not able to be networked, and so I found an article explaining how to enable the Docker Remote Access REST API on Ubuntu (http://www.virtuallyghetto.com/2014/07/quick-tip-how-to-enable-docker-remote-api.html). It explained how I needed to append DOCKER_OPTS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock'
to the file /etc/init/docker.conf
, however I have been unable to find this file on my Mac.
Any help or directions would be greatly appreciated,
Cheers
You need to set a DOCKER_HOST environment variable:
export DOCKER_HOST='-H unix:///var/run/docker.sock -H tcp://localhost:2376'
You can create a environment.plist
file in ~/Library/LaunchAgents/
to do that at system startup:
<?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>my.startup</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>
launchctl setenv DOCKER_HOST -H unix:///var/run/docker.sock -H tcp://localhost:2376
</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
这篇关于通过远程访问API访问Docker for Mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!