eval``$($ docker-machine env默认值)'' [英] eval "$(docker-machine env default)"

查看:56
本文介绍了eval``$($ docker-machine env默认值)''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用docker-compose启动docker时遇到问题.

I have issues with launching docker with docker-compose.

当我运行 docker-compose -f dev.yml build 时,出现以下错误>

When I run docker-compose -f dev.yml build I following error >

Building postgres
ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.

但是,如果我运行 docker-machine ls 机器显然已启动>

However if I run docker-machine ls machine is clearly up >

NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default   -        virtualbox   Running   tcp://192.168.99.100:2376           v1.12.1

我通过运行 eval"$(docker-machine env default)" 修复了错误,此后 docker-compose -f dev.yml build 成功完成.

I fixed the error by running eval "$(docker-machine env default)" after which docker-compose -f dev.yml build completes successfully.

我的问题是为什么要这样做,实际上会发生什么以及如何撤消它?

My question why did this work, what actually happens and how do I undo it?

这也是解决此问题的安全方法吗?现在这只是我的笔记本电脑,但是这些容器应该会在不久的将来袭击公司的服务器.

Also is this a safe way to fix this? Right now this just my laptop, but these containers are supposed to hit company servers in near future.

我对bash不太熟练,但总是被告知不要运行 eval ,尤其是不要使用"

I am not super fluent with bash but I been always told not to run eval and especially not to run eval with "

推荐答案

当您运行 docker 命令时,CLI连接到Docker守护程序的API,而实际上是由该API来完成工作的.您可以通过更改API连接详细信息从本地CLI管理远程Docker主机,该API连接详细信息将存储在Docker运行CLI的客户端的环境变量中.

When you run docker commands, the CLI connects to the Docker daemon's API, and it's the API that actually does the work. You can manage remote Docker hosts from your local CLI by changing the API connection details, which Docker stores in environment variables on the client where the CLI runs.

使用Docker Machine,您的Docker引擎运行在VM(实际上是一台远程计算机)中,因此需要配置您的本地CLI才能与其连接.Docker Machine知道其管理的引擎的连接详细信息,因此运行 docker-machine env default 会打印出 default 计算机的详细信息.输出是这样的:

With Docker Machine, your Docker engine is running in a VM, which is effectively a remote machine, so your local CLI needs to be configured to connect to it. Docker Machine knows the connection details for the engines it manages, so running docker-machine env default prints out the details for the default machine. The output is something like this:

 $ docker-machine env default
 export DOCKER_TLS_VERIFY="1"
 export DOCKER_HOST="tcp://172.16.62.130:2376"
 export DOCKER_CERT_PATH="/Users/elton/.docker/machine/machines/default"
 export DOCKER_MACHINE_NAME="default"

使用 eval 执行每个 export 命令,而不仅仅是将它们写入控制台,因此这是设置环境变量的快速方法.

Using eval executes each of those export commands, instead of just writing them to the console, so it's a quick way of setting up your environment variables.

您可以撤消它,并使用 docker-machine env --unset 重置本地环境,这会为您提供取消设置环境的输出(因此CLI会尝试连接到本地Docker Engine).

You can undo it and reset the local environment with docker-machine env --unset, which gives you the output for unsetting the environment (so the CLI will try to connect to the local Docker Engine).

这篇关于eval``$($ docker-machine env默认值)''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆