Add --shm-size to docker container update
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
Description
I'd like to easily change the shm-size in a running container by using docker container update. I'm running PostgreSQL inside a container and receiving an error related to the small amount of shared memory available.
Steps to reproduce the issue:
- Run any container you want to, without passing
--shm-size - Use some software inside the container to fill the 64MB shared memory available.
- Done, you're out of shared memory and you can't change it using the docker cli without destroying the container and creating a new one.
Describe the results you received:
I've found two ways of changing the shared memory of a running container:
-
Remount the shm file system of the container:
mount -o remount,rw,nosuid,nodev,noexec,relatime,size=256M -t tmpfs /var/lib/docker/containers/<container-id>/mounts/shm. Ifshmis not found inside this path, try usingnsenteras explained in https://github.com/docker/cli/issues/1278#issuecomment-1280877760 -
Change
ShmSizeinside/var/lib/docker/containers/<container-id>/hostconfig.jsonand restart container. EDIT: as noted by @dmitrygashnikov: you must stop docker service (service docker stop), then change thehostconfig.jsonfile for this container and start docker again (service docker start).
The second option is the only one which makes the change persistent, but we need to stop all running containers to make the change.
Here is a little script to change /dev/shm (by default to 1GB), using the docker daemon restart method:
#!/bin/bash
set -e
CONTAINER_NAME="$1"
if [ -z "$CONTAINER_NAME" ]; then
echo "ERROR - Usage: $0 <container-name> [shm-size]"
exit 1
fi
if [ ! -z "$2" ]; then
SHM_SIZE="$2"
else
SHM_SIZE="1073741824"
fi
echotime() {
echo [$(date "+%Y-%m-%d %H:%M:%S")] $@
}
CONTAINER_ID=$(docker inspect -f '{{ .ID }}' $CONTAINER_NAME)
HOST_CONFIG=/var/lib/docker/containers/$CONTAINER_ID/hostconfig.json
echotime "Stopping docker service"
service docker stop
echotime "Changing container's hostconfig.json"
sed -i 's/"ShmSize":[0-9]\+,/"ShmSize":'$SHM_SIZE',/' $HOST_CONFIG
echotime "Starting docker service"
service docker start
Describe the results you expected:
It would be awesome to change this setting from the command line, using docker container update --shm-size=256M.
Output of docker version:
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:17:14 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:15:24 2018
OS/Arch: linux/amd64
Experimental: false
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the docker container update command and its existing option handling; the issue names no implementation files or tests. Check how --shm-size is represented and updated, then verify that the requested command changes a running container without recreating it and preserves the setting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100