Docker Community Forums

Share and learn in the Docker community.

Possible to run containers at boot? And a networking question


I’m in an all-Mac environment and I want to start using Docker (finally also with a swarm with Docker processes on multiple Macs). I’m a newbie and I’ve been reading documentation and I’m left with a few questions for which I haven’t found answers yet. I’d be obliged if someone can answer them for me.

  1. I want containers to run at launch of the machine and not just when a user is logged in. From the documentation this looks to be incompatible with the Docker for Mac app, where all the documentation talks about ~/Library, etc. and everything seems to be about only running stuff when you’re logged in and have started the Docker for Mac app. Does this mean I will have to run Docker using the brew install? Or is it possible to have a Docker for Mac install and still use Docker containers without anyone being logged in?
  2. I want containers to be active on a local subnet. I’ve read that you cannot connect to containers from the macOS host Docker is running on. Is this final, or is it just a matter of the right routing table command and such? What is needed for containers on a Mac to be first class citizens on my local LAN?


Nobody? I’ve installed Docker through homebrew and have found out that apparently code signing stops launchd from starting a docker-machine at boot. It would be really nice if I could run a docker machine at boot and also start some containers at boot.


If you want your containers running all the time after a reboot then I would look at docker-compose this appears to work fine with a mac, not that I have any experience with macs.

Create a common network 'docker network create [some_network_name] ’ and then, instead of using docker run to start containers you would instead be using docker-compose.yml files which use a structured file to define paramaters such as volume mounts and environment variables. Also, the network to be used and any aliases.

Example: -

version: "3"
    image: "jwilder/nginx-proxy:alpine" 
    container_name: nginx
    restart: always 
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./nginx/log:/var/log/nginx/
      - ./nginx/certs:/etc/nginx/certs
      - ./nginx/proxy.conf:/etc/nginx/proxy.conf:ro
      - SSL_POLICY=Mozilla-Modern
      - '80:80'
      - '443:443'
          - nginx.local

          name: some_network

As far as I’m aware, assuming docker starts up when your machine boots, the assuming you started the docker containers using ‘docker-compose up -d’, in the same directory as the docker-compose.yml file, then these containers will spin up on boot. There’s also a restart: always option incase of crashes.


That is the second part. The first part is getting a docker-machine run at boot of the Mac, the “assuming docker starts up when your machine boots” part. That’s the one I haven’t been able to get running.

The codesign thing turned out to be a red herring, by the way. It’s just not possible to get a docker machine start running at boot time via launchd.


Actually, it is possible. The problem is that launchd has no mechanism for an ordering of what to launch at boot, no dependencies. And docker-machine launches are dependent on Virtualbox kernel extensions having loaded.

So, I wrote a script to handle docker-machine at launch (and in general) and now I can launch docker-machines at boot time of a mac. I’m still expanding on the script to handle more issues and when it’s done I’ll publish in full.