Skip to content

Instantly share code, notes, and snippets.

@slaughtr
Created January 4, 2022 01:29
Show Gist options
  • Save slaughtr/9e2806388359429049320ae68823e50b to your computer and use it in GitHub Desktop.
Save slaughtr/9e2806388359429049320ae68823e50b to your computer and use it in GitHub Desktop.
Docker for Mac - use DOCKER_CONFIG var

Docker for Mac does not respect the DOCKER_CONFIG var - docker/for-mac#2635

However, using launchctl you can get the desktop app to use a different .docker location.

  • Create a plist file, I use environment.plist as I use this workaround for other apps.
  • Insert the following into the plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
        <dict>
                <key>Label</key>
                <string>my.startup</string>
                <key>ProgramArguments</key>
                <array>
                        <string>sh</string>
                        <string>-c</string>
                        <string>
                                launchctl setenv DOCKER_CONFIG /Users/myuser/.config/docker
                        </string>
                </array>
                <key>RunAtLoad</key>
                <true/>
        </dict>
</plist>
  • Move the file to the LaunchAgents folder (optional, but recommended) mv environment.plist ~/Library/LaunchAgents/
  • Start the agent launchctl start ~/Library/LaunchAgents/environment.plist

Now, when you open Docker (or any other app!), the DOCKER_CONFIG variable will be set to the value you provide, and Docker will use the proper path for the config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment