简体   繁体   English

eval“$(docker-machine env default)”

[英]eval “$(docker-machine env default)”

I have issues with launching docker with docker-compose. 我有使用docker-compose启动docker的问题。

When I run docker-compose -f dev.yml build I following error > 当我运行docker-compose -f dev.yml build我跟随错误>

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

However if I run docker-machine ls machine is clearly up > 但是,如果我运行docker-machine ls机器显然是>

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

I fixed the error by running eval "$(docker-machine env default)" after which docker-compose -f dev.yml build completes successfully. 我通过运行eval "$(docker-machine env default)"修复了错误,之后docker-compose -f dev.yml build成功完成。

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. 现在这只是我的笔记本电脑,但这些容器应该在不久的将来打到公司的服务器。

I am not super fluent with bash but I been always told not to run eval and especially not to run eval with " 我不是非常流利的bash,但我总是被告知不要运行eval ,特别是不要运行eval与“

When you run docker commands, the CLI connects to the Docker daemon's API, and it's the API that actually does the work. 当您运行docker命令时,CLI将连接到Docker守护程序的API,它是实际完成工作的API。 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. 您可以通过更改API连接详细信息来管理本地CLI中的远程Docker主机,Docker存储在运行CLI的客户端上的环境变量中。

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,您的Docker引擎在VM中运行,VM实际上是远程计算机,因此需要将本地CLI配置为连接到它。 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. Docker Machine知道它管理的引擎的连接细节,因此运行docker-machine env default打印出default机器的详细信息。 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"

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. 使用eval执行每个export命令,而不是仅将它们写入控制台,因此这是设置环境变量的快捷方法。

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). 您可以使用docker-machine env --unset撤消它并重置本地环境,这会为您提供取消设置环境的输出(因此CLI将尝试连接到本地Docker引擎)。

This is indeed the expected way to use Docker on a machine that does not natively support Docker, eg on Windows or Mac OS X. 这确实是在本机上不支持Docker的机器上使用Docker的预期方法,例如在Windows或Mac OS X上。

The Docker documentation includes this step in its description for using Docker Machine here: https://docs.docker.com/machine/get-started/ Docker文档在其描述中包含了使用Docker Machine的步骤: https//docs.docker.com/machine/get-started/

What this step does (I suggest you also try this yourself): 这一步做了什么(我建议你自己试试):

  • Run docker-machine env default . 运行docker-machine env default
  • Take the output of that command and execute it in the current shell session. 获取该命令的输出并在当前shell会话中执行它。

If you run docker-machine env default yourself, you will see that it simply suggests to set some environment variables, which allow the Docker commands to find the VM running the Docker daemon. 如果你自己运行docker-machine env default ,你会发现它只是建议设置一些环境变量,这些变量允许Docker命令找到运行Docker守护进程的VM。 Without these variables set, Docker simply does not know how to communicate with the Docker daemon. 如果没有设置这些变量,Docker根本不知道如何与Docker守护进程通信。

In a server environment (Linux), you will not need Docker Machine, since the Linux kernel natively supports running containers. 在服务器环境(Linux)中,您不需要Docker Machine,因为Linux内核本身支持运行容器。 You only need Docker Machine (a small VM running a Linux kernel) on operating systems that don't natively support running containers. 您只需要在本机上不支持运行容器的操作系统上使用Docker Machine(运行Linux内核的小型VM)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM