I'm currently having some issues with the shared memory in one of my containers.
I have a docker-compose file in where I expect to be able to set the size. I basically converted an old docker run that had a --shm-size 16gb
. I would guess it's as easy as adding shm_size:16gb
to my service in the compose file.
Adding it just gives me the info: Ignoring unsupported options: shm_size
.
I did check the docs, but it didn't really help me.
Just to clarify, it's not in the build but really for the "running" state.
Does one of you ever had this issue/know how to solve it?
Setup:
Compose file:
version: "3.7"
services:
server:
shm_size: 16GB # <<<<<<< This fails
image: local_repo/my_app:v1-dev
command: run
environment:
- UPDATES=enabled
volumes:
- type: volume
source: data
target: /var/lib/my_app/
- type: volume
source: db
target: /var/lib/postgresql/10/main
networks:
- xxx_traefik
deploy:
mode: replicated
labels:
- traefik.docker.network=xxx_traefik
- traefik.enable=true
- traefik.port=80
- traefik.frontend.rule=Host:my_container.xxx.com
- traefik.backend.loadbalancer.stickiness=true
- traefik.protocol=http
replicas: 1
placement:
constraints:
- node.hostname==node2
volumes:
db:
external: true
data:
external: true
networks:
xxx_traefik:
external: true
# shm_size: 16GB <<<<<<< Also tried to put it here since documentation doesn't show indents
Any help is appreciated:)
To limit the maximum amount of memory usage for a container, add the --memory option to the docker run command. Alternatively, you can use the shortcut -m . Within the command, specify how much memory you want to dedicate to that specific container.
Docker containers are allocated 64 MB of shared memory by default.
Before getting into mem_limit docker compose let us take a look at mem_limit. Memory Limit or mem-limit, in general, imposes an upper limit on the amount of memory that a Docker container can potentially use.
The minimum allowed value is 4m . Because kernel memory cannot be swapped out, a container which is starved of kernel memory may block host machine resources, which can have side effects on the host machine and on other containers.
It should be below service, I can verify it, but here is what offical documentation said
SHM_SIZE
Added in version 3.5 file format
Set the size of the /dev/shm partition for this build’s containers. Specify as an integer value representing the number of bytes or as a string expressing a byte value.
build:
context: .
shm_size: '2gb'
compose-file-SHM_SIZE
Here is test
version: '3.7'
services:
your_service:
image: alpine
command: ash -c "sleep 2 && df /dev/shm"
shm_size: 2gb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With