I have issues with launching docker with docker-compose.
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`.
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
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.
I am not super fluent with bash but I been always told not to run eval
and especially not to run eval with "
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. Without these variables set, Docker simply does not know how to communicate with the Docker daemon.
Set environment variables to dictate that docker should run a command against a particular machine. docker-machine env machinename prints out export commands which can be run in a subshell. Running docker-machine env -u prints unset commands which reverse this effect.
The command minikube docker-env returns a set of Bash environment variable exports to configure your local environment to re-use the Docker daemon inside the Minikube instance. Passing this output through eval causes bash to evaluate these exports and put them into effect.
Docker-Machine is a tool that lets you install Docker Engine on Virtual Hosts. We'll outline how we deploy containers and how to transfer files to/from the machine.
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.
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"
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With