Search code examples
batch-filedockerdocker-machine

How to setup default environment quickly in Docker?


Currently when I do almost any docker command (e.g. docker ps) I get the following error message:

An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/containers/json: open //./pipe/docker_engine: The system cannot find the file specified.

To solve this issue I have to run the following command:

@FOR /f "tokens=*" %i IN ('docker-machine env') DO @%i

Becuase I do this so often, I decided to put this is a .bat script called setup-docker-env.bat

However whenever I run that script I get the following error:

i was unexpected at this time.

This is odd as it works on the command line.


Solution

  • In batch files replace % with %% on FOR statements