How to add swap to docker?

September 20, 2018 2.5k views
MySQL Apache Docker

Guys hi,

I am using Ubuntu Docker 17.12.0ce on 16.04 and have php app running.
It has 2 containers: prj_apache_1 and prj1_mysql_1

Problem is that mysql container is frequently crushing. Solution is to add swap space.
But most of explanation are for “regular” server not dockerized.

I do not have root@myserver:~#,

i have root@docker-s-1vcpu-1gb-nyc3-01:~#,
also i can “get in” apache using docker exec -ti prj_apache_1 bash
and mysql docker exec -ti prj_mysql_1 bash

so my question inside which containers do i run this commands: ?

1 Answer

Hey friend!

Docker is going to use the host memory/swap, so you can just add swap to the VM or increase memory. Note that swap is kind of a bad thing if you’re frequently going OOM. You want swap to do less important things than frequently act on behalf of memory missing and needed. Increasing memory in the VM or further optimizing the MySQL configuration (or even the app that is using MySQL) will continue to be superior solutions.


Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!