Yahya Uddin
Yahya Uddin

Reputation: 28901

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.

Upvotes: 0

Views: 363

Answers (2)

mandark
mandark

Reputation: 782

The % chars need to be escaped. Your .bat file needs to have the following contents:

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

Upvotes: 1

Gerardo Grignoli
Gerardo Grignoli

Reputation: 15197

In batch files replace % with %% on FOR statements

Upvotes: 3

Related Questions