Skip to content

Instantly share code, notes, and snippets.

@smnorris
Created November 30, 2021 04:18
Show Gist options
  • Select an option

  • Save smnorris/69f93a3a39938f9485f04b724693fb9a to your computer and use it in GitHub Desktop.

Select an option

Save smnorris/69f93a3a39938f9485f04b724693fb9a to your computer and use it in GitHub Desktop.

docker update shared memory on mac

Bigger parallel postgres queries can run out of memory because the Docker VM only has 1G shared memory as default. To fix, update the shm_size.

First, update docker-compose.yml to set the shm_size when creating containers:

        services:
          db:
            image: postgis/postgis:14-master
            shm_size: 16gb

To update shared mem on an existing container without re-creating: docker/cli#1278 https://stackoverflow.com/questions/63445657/why-i-am-getting-screen-is-terminating-error-in-macos

    # find container id
    $ CONTAINER_ID=$(docker inspect -f '{{ .ID }}' $CONTAINER_NAME)

    # note it
    $ echo $CONTAINER_ID
    de0600a1549800786080a1dbe60253b1c96e4e897a24f6a8f1405295546c1a80

    # log in to vm
    $ docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh

    # find container config
    cd /var/lib/docker/containers/de0600a1549800786080a1dbe60253b1c96e4e897a24f6a8f1405295546c1a80
    ls

    checkpoints                                                                hosts
    config.v2.json                                                             mounts
    de0600a1549800786080a1dbe60253b1c96e4e897a24f6a8f1405295546c1a80-json.log  resolv.conf
    hostconfig.json                                                            resolv.conf.hash
    hostname

    # change the value
    echotime "Changing container's hostconfig.json"
    sed -i 's/"ShmSize":[0-9]\+,/"ShmSize":'16gb',/' hostconfig.json
    exit

Restart docker after making the change

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