Skip to content
TheChatArchiveThe Chat Archive
Googlegemma-3-27b-it· GoogleHugging Face LMArena Human Preference 140K

How to run Docker daemon automatically when MacOS starts without Docker Desktop

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with DeepSeekdeepseek-v3-0324’s answer.
  1. User

    How to run Docker daemon automatically when MacOS starts without Docker Desktop

  2. Google Assistant

    Okay, here's a breakdown of how to run the Docker daemon automatically on macOS at startup without relying on Docker Desktop. This is a more advanced setup, but it gives you more control and can be lighter-weight. I'll cover several methods, from simpler to more robust, along with explanations and considerations.

    Important Considerations Before You Start:

    • Security: Running Docker as root is generally discouraged. We'll focus on running it as a non-root user.
    • Complexity: This is more involved than using Docker Desktop. You'll need to be comfortable with the command line and potentially editing system configuration files.
    • Updates: You'll be responsible for manually updating the Docker engine itself. Docker Desktop handles this automatically.
    • Networking: Docker Desktop provides convenient networking features. You might need to configure networking manually.
    • Compatibility: Ensure the Docker version you install is compatible with your macOS version.
    • Alternatives: Consider using Podman as a drop-in replacement for Docker. Podman is rootless by default and integrates well with systemd (which we'll touch on).

    Method 1: LaunchAgent (Simplest, but less robust)

    This is the easiest method to get started, but it's not the most reliable. LaunchAgents are macOS's mechanism for running processes at login.

    1. Install Docker Engine: If you haven't already, install the Docker engine. The most common way is using Homebrew:

      brew install docker
      
    2. Create a LaunchAgent plist file: Create a file named com.docker.engine.plist in the ~/Library/LaunchAgents/ directory. You can use a text editor (like nano, vim, or TextEdit).

      <?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>com.docker.engine</string>
          <key>ProgramArguments</key>
          <array>
              <string>/usr/local/bin/dockerd</string>  <!-- Adjust path if necessary -->
          </array>
          <key>RunAtLoad</key>
          <true/>
          <key>KeepAlive</key>
          <true/>
          <key>StandardOutPath</key>
          <string>/tmp/docker.log</string>
          <key>StandardErrorPath</key>
          <string>/tmp/docker.err</string>
      </dict>
      </plist>
      
      • Label: A unique identifier for the LaunchAgent.
      • ProgramArguments: The command to run. Make sure /usr/local/bin/dockerd is the correct path to your Docker daemon executable. Use which dockerd to verify.
      • RunAtLoad: true means the process will start when you log in.
      • KeepAlive: true means the process will be restarted if it crashes.
      • StandardOutPath and StandardErrorPath: Redirect output and errors to log files for debugging.
    3. Load the LaunchAgent:

      launchctl load ~/Library/LaunchAgents/com.docker.engine.plist
      
    4. Test: Log out and log back in. Then, check if the Docker daemon is running:

      docker info
      

      If it works, you should see Docker information. If not, check the log files (/tmp/docker.log and /tmp/docker.err) for errors.

    5. To stop the LaunchAgent:

      launchctl unload ~/Library/LaunchAgents/com.docker.engine.plist
      

    Method 2: Using systemd (More Robust, Requires Extra Setup)

    systemd is a system and service manager commonly used on Linux. While macOS doesn't natively use systemd, you can install a compatibility layer called brew services. This is the most robust method, but it requires more initial setup.

    1. Install brew services:

      brew install brew-services
      
    2. Create a systemd service file: Create a file named docker.service in /opt/homebrew/etc/systemd/system/ (or wherever brew services installs its service files).

      [Unit]
      Description=Docker Engine
      After=network-online.target
      Wants=network-online.target
      
      [Service]
      Type=simple
      ExecStart=/usr/local/bin/dockerd
      Restart=on-failure
      User=your_user  # Replace with your macOS username
      Group=staff
      
      [Install]
      WantedBy=multi-user.target
      
      • Description: A human-readable description of the service.
      • After and Wants: Ensure the network is up before starting Docker.
      • ExecStart: The command to run. Adjust the path if necessary.
      • Restart: Restart the service if it fails.
      • User and Group: Crucially, replace your_user with your actual macOS username. This runs Docker as your user, not as root. staff is a common group.
      • WantedBy: Indicates when the service should be started.
    3. Enable and Start the Service:

      brew services start docker
      
    4. Check Status:

      brew services list
      

      This should show Docker running. You can also use:

      systemctl status docker
      
    5. To stop the service:

      brew services stop docker
      

    Method 3: Using launchd with a more sophisticated script (Advanced)

    This method involves creating a more complex script that handles potential errors and dependencies. It's more reliable than the simple LaunchAgent but requires more scripting knowledge.

    1. Install Docker Engine (as in Method 1).

    2. Create a script: Create a script (e.g., ~/bin/start_docker.sh) with the following content:

      #!/bin/bash
      
      # Check if Docker is already running
      if pgrep dockerd > /dev/null; then
        echo "Docker is already running."
        exit 0
      fi
      
      # Start Docker
      /usr/local/bin/dockerd &
      
      # Check if Docker started successfully
      sleep 5  # Give Docker some time to start
      if pgrep dockerd > /dev/null; then
        echo "Docker started successfully."
      else
        echo "Failed to start Docker."
        exit 1
      fi
      

      Make the script executable:

      chmod +x ~/bin/start_docker.sh
      
    3. Create a LaunchAgent plist file (similar to Method 1):

      <?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>com.docker.engine</string>
          <key>ProgramArguments</key>
          <array>
              <string>/bin/bash</string>
              <string>/Users/your_user/bin/start_docker.sh</string>  <!-- Replace with your username -->
          </array>
          <key>RunAtLoad</key>
          <true/>
          <key>KeepAlive</key>
          <true/>
          <key>StandardOutPath</key>
          <string>/tmp/docker.log</string>
          <key>StandardErrorPath</key>
          <string>/tmp/docker.err</string>
      </dict>
      </plist>
      
      • Replace your_user with your macOS username.
    4. Load the LaunchAgent (as in Method 1).

    5. Test and check logs (as in Method 1).

    Troubleshooting Tips:

    • Permissions: Ensure the user running Docker has the necessary permissions to access the Docker socket (/var/run/docker.sock). If you're using a non-root user, you might need to add them to the docker group (though this is less common with modern Docker installations).
    • Conflicts: Make sure no other processes are trying to bind to the same ports as Docker.
    • Logs: The log files (/tmp/docker.log and /tmp/docker.err in the examples) are your best friend for debugging.
    • docker info: Use docker info to check if the Docker daemon is running and accessible.
    • Firewall: Ensure your firewall isn't blocking Docker's communication.
    • Homebrew: If you used Homebrew, make sure Homebrew itself is up to date (brew update).

    Recommendation:

    I recommend starting with Method 2 (using brew services and systemd) if you're comfortable with the initial setup. It's the most robust and reliable way to run Docker automatically on macOS without Docker Desktop. If you want a simpler approach, Method 1 (LaunchAgent) is a good starting point, but be aware of its limitations. Method 3 is for more advanced users who want fine-grained control.

    Remember to replace placeholders (like your username and paths) with your actual values. Good luck!

  3. User

    /usr/local/bin/dockerd is not available, I don't think all the method are workable.

  4. Google Assistant

    You are absolutely right to point that out! My apologies. /usr/local/bin/dockerd is a common assumption, but with recent changes in how Homebrew and Docker are installed on Apple Silicon (M1/M2/M3) and even on Intel Macs, it's often not where the dockerd executable resides.

    Let's address this and revise the instructions. The correct path is usually within the Homebrew Cellar. Here's how to find it and adjust the methods:

    1. Find the dockerd executable:

    Run this command in your terminal:

    which dockerd
    

    This will output the full path to the dockerd executable. It will likely be something like:

    • /opt/homebrew/Cellar/docker/24.0.7/bin/dockerd (Apple Silicon)
    • /usr/local/Cellar/docker/24.0.7/bin/dockerd (Intel)

    (The 24.0.7 part will be your installed Docker version number.)

    2. Update the Methods:

    Now, let's revise the methods using the correct path. I'll provide updated instructions for each.

    Method 1: LaunchAgent (Revised)

    1. Install Docker Engine: (As before: brew install docker)

    2. Create a LaunchAgent plist file: (in ~/Library/LaunchAgents/com.docker.engine.plist)

      <?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>com.docker.engine</string>
          <key>ProgramArguments</key>
          <array>
              <string>/opt/homebrew/Cellar/docker/24.0.7/bin/dockerd</string>  <!-- REPLACE WITH YOUR ACTUAL PATH -->
          </array>
          <key>RunAtLoad</key>
          <true/>
          <key>KeepAlive</key>
          <true/>
          <key>StandardOutPath</key>
          <string>/tmp/docker.log</string>
          <key>StandardErrorPath</key>
          <string>/tmp/docker.err</string>
      </dict>
      </plist>
      

      Important: Replace /opt/homebrew/Cellar/docker/24.0.7/bin/dockerd with the output of the which dockerd command you ran earlier.

    3. Load the LaunchAgent:

      launchctl load ~/Library/LaunchAgents/com.docker.engine.plist
      
    4. Test: Log out and log back in. Then, check if the Docker daemon is running:

      docker info
      

    Method 2: Using systemd (Revised)

    1. Install brew services: (As before: brew install brew-services)

    2. Create a systemd service file: (in /opt/homebrew/etc/systemd/system/docker.service)

      [Unit]
      Description=Docker Engine
      After=network-online.target
      Wants=network-online.target
      
      [Service]
      Type=simple
      ExecStart=/opt/homebrew/Cellar/docker/24.0.7/bin/dockerd  <!-- REPLACE WITH YOUR ACTUAL PATH -->
      Restart=on-failure
      User=your_user  # Replace with your macOS username
      Group=staff
      
      [Install]
      WantedBy=multi-user.target
      

      Important: Replace /opt/homebrew/Cellar/docker/24.0.7/bin/dockerd with the output of the which dockerd command.

    3. Enable and Start the Service:

      brew services start docker
      
    4. Check Status:

      brew services list
      

    Method 3: Using launchd with a script (Revised)

    1. Install Docker Engine (as before).

    2. Create a script: (e.g., ~/bin/start_docker.sh)

      #!/bin/bash
      
      # Check if Docker is already running
      if pgrep dockerd > /dev/null; then
        echo "Docker is already running."
        exit 0
      fi
      
      # Start Docker
      /opt/homebrew/Cellar/docker/24.0.7/bin/dockerd &  <!-- REPLACE WITH YOUR ACTUAL PATH -->
      
      # Check if Docker started successfully
      sleep 5  # Give Docker some time to start
      if pgrep dockerd > /dev/null; then
        echo "Docker started successfully."
      else
        echo "Failed to start Docker."
        exit 1
      fi
      

      Make the script executable:

      chmod +x ~/bin/start_docker.sh
      
    3. Create a LaunchAgent 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>com.docker.engine</string>
          <key>ProgramArguments</key>
          <array>
              <string>/bin/bash</string>
              <string>/Users/your_user/bin/start_docker.sh</string>  <!-- Replace with your username -->
          </array>
          <key>RunAtLoad</key>
          <true/>
          <key>KeepAlive</key>
          <true/>
          <key>StandardOutPath</key>
          <string>/tmp/docker.log</string>
          <key>StandardErrorPath</key>
          <string>/tmp/docker.err</string>
      </dict>
      </plist>
      

      Replace your_user with your macOS username.

    4. Load the LaunchAgent (as before).

    Key Takeaway:

    The most important step is to always use the output of which dockerd to determine the correct path to the Docker daemon executable. Don't assume it's in /usr/local/bin/.

    I apologize again for the initial incorrect information. I should have emphasized the importance of verifying the path. Let me know if you encounter any further issues after updating the paths.

  5. User

    dockerd is not installed by brew install docker.

  6. Google Assistant

    You are absolutely correct! My apologies for the continued errors. It seems I'm stuck in a pattern of incorrect assumptions. brew install docker installs the Docker CLI client, not the dockerd daemon itself. The daemon is installed as part of the docker-compose package, or can be installed separately.

    Let's correct this and get you running. Here's the revised approach:

    1. Install the Docker Engine (Daemon):

    Instead of just brew install docker, you need to install docker-compose. This will pull in the dockerd daemon as a dependency.

    brew install docker-compose
    

    Alternatively, you can install the daemon directly:

    brew install docker
    

    2. Find the dockerd executable (Again!):

    After installation, run which dockerd to find the correct path. It will likely be in one of these locations:

    • /opt/homebrew/Cellar/docker/VERSION/bin/dockerd (Apple Silicon)
    • /usr/local/Cellar/docker/VERSION/bin/dockerd (Intel)

    Replace VERSION with your installed Docker version number.

    3. Update the Methods (Using the Correct Path):

    Now, let's revise the methods using the correct path you found in step 2. I'll provide updated instructions for each.

    Method 1: LaunchAgent (Revised)

    1. Install Docker Engine: (As above: brew install docker-compose or brew install docker)

    2. Create a LaunchAgent plist file: (in ~/Library/LaunchAgents/com.docker.engine.plist)

      <?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>com.docker.engine</string>
          <key>ProgramArguments</key>
          <array>
              <string>/opt/homebrew/Cellar/docker/VERSION/bin/dockerd</string>  <!-- REPLACE WITH YOUR ACTUAL PATH -->
          </array>
          <key>RunAtLoad</key>
          <true/>
          <key>KeepAlive</key>
          <true/>
          <key>StandardOutPath</key>
          <string>/tmp/docker.log</string>
          <key>StandardErrorPath</key>
          <string>/tmp/docker.err</string>
      </dict>
      </plist>
      

      Important: Replace /opt/homebrew/Cellar/docker/VERSION/bin/dockerd with the output of the which dockerd command you ran earlier.

    3. Load the LaunchAgent:

      launchctl load ~/Library/LaunchAgents/com.docker.engine.plist
      
    4. Test: Log out and log back in. Then, check if the Docker daemon is running:

      docker info
      

    Method 2: Using systemd (Revised)

    1. Install brew services: (As before: brew install brew-services)

    2. Create a systemd service file: (in /opt/homebrew/etc/systemd/system/docker.service)

      [Unit]
      Description=Docker Engine
      After=network-online.target
      Wants=network-online.target
      
      [Service]
      Type=simple
      ExecStart=/opt/homebrew/Cellar/docker/VERSION/bin/dockerd  <!-- REPLACE WITH YOUR ACTUAL PATH -->
      Restart=on-failure
      User=your_user  # Replace with your macOS username
      Group=staff
      
      [Install]
      WantedBy=multi-user.target
      

      Important: Replace /opt/homebrew/Cellar/docker/VERSION/bin/dockerd with the output of the which dockerd command.

    3. Enable and Start the Service:

      brew services start docker
      
    4. Check Status:

      brew services list
      

    Method 3: Using launchd with a script (Revised)

    1. Install Docker Engine: (As above: brew install docker-compose or brew install docker)

    2. Create a script: (e.g., ~/bin/start_docker.sh)

      #!/bin/bash
      
      # Check if Docker is already running
      if pgrep dockerd > /dev/null; then
        echo "Docker is already running."
        exit 0
      fi
      
      # Start Docker
      /opt/homebrew/Cellar/docker/VERSION/bin/dockerd &  <!-- REPLACE WITH YOUR ACTUAL PATH -->
      
      # Check if Docker started successfully
      sleep 5  # Give Docker some time to start
      if pgrep dockerd > /dev/null; then
        echo "Docker started successfully."
      else
        echo "Failed to start Docker."
        exit 1
      fi
      

      Make the script executable:

      chmod +x ~/bin/start_docker.sh
      
    3. Create a LaunchAgent 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>com.docker.engine</string>
          <key>ProgramArguments</key>
          <array>
              <string>/bin/bash</string>
              <string>/Users/your_user/bin/start_docker.sh</string>  <!-- Replace with your username -->
          </array>
          <key>RunAtLoad</key>
          <true/>
          <key>KeepAlive</key>
          <true/>
          <key>StandardOutPath</key>
          <string>/tmp/docker.log</string>
          <key>StandardErrorPath</key>
          <string>/tmp/docker.err</string>
      </dict>
      </plist>
      

      Replace your_user with your macOS username.

    4. Load the LaunchAgent (as before).

    Again, the most important step is to use the output of which dockerd to determine the correct path.

    I sincerely apologize for the repeated errors. I am still under development and learning to provide accurate information. I hope this revised set of instructions finally gets you up and running! Please let me know if you encounter any further issues.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.