Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait-for-docker doesn't recognize active Docker process with Docker Desktop on macOS #12

Closed
gh640 opened this issue May 17, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@gh640
Copy link
Owner

gh640 commented May 17, 2023

wait-for-docker doesn't recognize the active Docker process though it's running.

To investigate, I tried running docker.from_env() (that is used internally in wait-for-docker) in Python console. docker.from_env() raised the following error:

❯ python
Python 3.11.3 (main, Apr 25 2023, 17:01:01) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import docker
>>> docker.from_env()
Traceback (most recent call last):
  File "/var/venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
  File "/var/venv/lib/python3.11/site-packages/urllib3/connection.py", line 388, in request
    self.endheaders()
  File "/path/to/python/3.11.3/lib/python3.11/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/path/to/python/3.11.3/lib/python3.11/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/path/to/python/3.11.3/lib/python3.11/http/client.py", line 976, in send
    self.connect()
  File "/var/venv/lib/python3.11/site-packages/docker/transport/unixconn.py", line 27, in connect
    sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/venv/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/urllib3/util/retry.py", line 470, in increment
    raise reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/urllib3/util/util.py", line 38, in reraise
    raise value.with_traceback(tb)
  File "/var/venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
  File "/var/venv/lib/python3.11/site-packages/urllib3/connection.py", line 388, in request
    self.endheaders()
  File "/path/to/python/3.11.3/lib/python3.11/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/path/to/python/3.11.3/lib/python3.11/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/path/to/python/3.11.3/lib/python3.11/http/client.py", line 976, in send
    self.connect()
  File "/var/venv/lib/python3.11/site-packages/docker/transport/unixconn.py", line 27, in connect
    sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/venv/lib/python3.11/site-packages/docker/api/client.py", line 214, in _retrieve_server_version
    return self.version(api_version=False)["ApiVersion"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/docker/api/daemon.py", line 181, in version
    return self._result(self._get(url), json=True)
                        ^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/docker/api/client.py", line 237, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/requests/sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/venv/lib/python3.11/site-packages/docker/client.py", line 96, in from_env
    return cls(
           ^^^^
  File "/var/venv/lib/python3.11/site-packages/docker/client.py", line 45, in __init__
    self.api = APIClient(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/docker/api/client.py", line 197, in __init__
    self._version = self._retrieve_server_version()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/venv/lib/python3.11/site-packages/docker/api/client.py", line 221, in _retrieve_server_version
    raise DockerException(
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

Environment

❯ sw_vers
ProductName:		macOS
ProductVersion:		13.3.1
ProductVersionExtra:	(a)
BuildVersion:		22E772610a
@gh640 gh640 added the bug Something isn't working label May 17, 2023
@gh640 gh640 self-assigned this May 17, 2023
@gh640 gh640 changed the title wait-for-docker doesn't recognize active Docker process wait-for-docker doesn't recognize active Docker process with Docker Desktop on macOS May 17, 2023
@gh640
Copy link
Owner Author

gh640 commented May 17, 2023

The cause is that the path of the docker.sock had been changed.

One workaround is to create a symlink:

sudo ln -s "$HOME/.docker/run/docker.sock" /var/run/docker.sock

@gh640
Copy link
Owner Author

gh640 commented May 17, 2023

According to the release notes, this problem was already solved.

Excerpts:

4.14.0:

  • Re-added the /var/run/docker.sock on Mac by default, to increase compatibility with tooling like tilt and docker-py.

4.13.0:

  • By default Docker will not create the /var/run/docker.sock symlink on the host and use the docker-desktop CLI context instead.

In my case, the problem occurred as the setting item (for /var/run/docker.sock) referred to in the next comment was not enabled.

@gh640
Copy link
Owner Author

gh640 commented May 17, 2023

One needs to enable "Enable default Docker socket (Requires password)" in "Advanced" section in Docker Desktop settings to make a symbolic link /var/run/docker.sock on startup:

Screenshot by Dropbox Capture

Ref:

You are also given the option to enable the installation of the /var/run/docker.sock symlink. Creating this symlink ensures various Docker clients relying on the default Docker socket path to work without additional changes.

As the /var/run is mounted as a tmpfs, its content is deleted on restart, symlink to the Docker socket included. To ensure the Docker socket exists after restart, Docker Desktop sets up a launchd startup task that creates the symlink by running ln -s -f /Users/<user>/.docker/run/docker.sock /var/run/docker.sock. This ensures the user is not prompted on each startup to create the symlink. If the user does not enable this option at installation, the symlink and the startup task is not created and the user may have to explicitly set the DOCKER_HOST environment variable to /Users/<user>/.docker/run/docker.sock in the clients it is using. The Docker CLI relies on the current context to retrieve the socket path, the current context is set to desktop-linux on Docker Desktop startup.

https://docs.docker.com/desktop/mac/permission-requirements/


The actual .plist file used seems to be /Library/LaunchDaemons/com.docker.socket.plist in my environment. The file looks like the following (pretty-formatted):

<?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>KeepAlive</key>
        <false/>
        <key>Label</key>
        <string>com.docker.socket</string>
        <key>ProcessType</key>
        <string>Background</string>
        <key>Program</key>
        <string>/Library/PrivilegedHelperTools/com.docker.socket</string>
        <key>ProgramArguments</key>
        <array>
            <string>/Library/PrivilegedHelperTools/com.docker.socket</string>
        <string>/Users/[username]/.docker/run/docker.sock</string>
        <string>/var/run/docker.sock</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>ServiceDescription</key>
        <string>Docker ServiceDescription</string>
    </dict>
</plist>

@gh640 gh640 closed this as completed May 18, 2023
@gh640
Copy link
Owner Author

gh640 commented May 26, 2023

Also the item "Docker Inc" in System Settings → General → Login Items → Allow in the Background needs to be enabled (it's enabled by default):

Screenshot by Dropbox Capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant