Docker for Mac clock drift fix

It’s a pain, not sure if there is a “real” fix, but if your Docker host and Mac host clocks drift (presumably the Mac is correct), you can run:

docker run --privileged --rm alpine date -s "$(date -u "+%Y-%m-%d %H:%M:%S")"

I’ve seen differences over 5 minutes, so worth checking…

Docker for Mac fix for max files, transparent hugepages warnings

To avoid Redis and other apps’ “max files limit” and “transparent hugepages” etc errors in Docker containers on Docker for Mac, you can set sysctls options in your docker-compose file by using compose format 2.1 or greater, which should be supported in docker-compose >= 1.10.

in docker-compose.yml file:

version: '2.1'
services:
  redis:
    image: redis:3.2-alpine
    command: redis-server /usr/local/etc/redis/redis.conf
    sysctls:
      - net.core.somaxconn=1024

To update transparent hugepages settings in Docker for Mac’s Alpine hypervisor host system, you can use this hack:

docker run --rm --privileged -ti alpine /bin/sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled && echo never > /sys/kernel/mm/transparent_hugepage/defrag"

In theory you wouldn’t need/want to do this on a production host as you would configure the host properly. If you update Docker, you will need to re-run this.

Connect to Docker for Mac Alpine Host

The new Docker for Mac (mid-2016) doesn’t work the same way as previous versions or the native linux version. To interact with the Docker Host VM, instead of SSH, you can use:

screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

and login with root user. No password should be required.
use Control-a d to detach.

You can also get networking, etc info about the host by querying a container host-networked like so:

docker run --rm --privileged --net=host alpine ifconfig