How to limit resource use for a container
like the title said, I run coder with
here is my template structure as default:
I need a container run as long as I need it too, but looking at htop
coder-server/something/node
got around half of my ram, so I want to limit them a bit ( maybe 12gb ) ? How can I do that ?
10 Replies
You can limit memory of docker workspaces by setting
memory
attribute of docker_container
resource.
Check the docker terraform provider docs for more info.found it, thanks!
kindda lazy to open another thread but, i always run coder on my local machine, now I want to move to docker compose:
/home/ser3_decoyer/.config/coderv2/postgresql/data:/var/lib/postgresql/data
I tried to mount my current data to migrate to docker compose postgresql but it seems like all my template and container disappear (i can login tho, so I guess it work?), how should I migrate template and the running container ?
should I just open another thread😅 feel like this issue is small for a thread tbh
Coder stores all templates and other data in the database, so if templates are not showing up, something is wrong.
oh hey i just realize ive been running a pretty old coder version (v2.7.something), it usting postgres 13 while the current coder in docker compose using postgres 16, so obviously it wont work lol
im looking into how to dump data rn, i'll come back if I cant figure it out lol
hi, I got some logs:
seems like v1.7 to v2.20 is a huge jump, any advice of how to restore db ?
you can just dump it and restore it
using pg_dump
Hello:) thank you,
I gave on restoring it tho, after dumping, i got some locacle issue, duplicate "coder" table, then I tried to pg_upgrade it and there were whole bunch of other errors
I'm willing to share my dump if anyone interested to try pg_upgrade
have you tried importing something else prior to importing that dump?
you could've but let's keep it here
ok here is my attempt:
1. I thought if I just mounted or copied from the Postgres directory (from
Postgres 16 is natively available in Noble (Ubuntu 24), so it was pretty easy to install.
As for Postgres 13 — it doesn’t have a candidate package for Noble, so I had to install it via the Postgres repo (again, I forgot the exact steps, but I managed to install it).
The result was pretty much the same as in section 2 — a whole bunch of unknown/invalid key errors, locale issues, and
~/.config/coderv2/postgres/data:/var/lib/postgresql/data
), everything would transfer fine. But it hit me with an error about incompatible DB versions. Ok, cool — version 13 can't be merged with version 16 that easily. Then I looked it up on Google to learn how to dump the DB.
2. So essentially, there are two ways to recover the DB — either you recover only the data or the entire DB:
2.1 I tried to recover only the data first. So I had to boot up Postgres 16. Then I ran docker compose up -d database
, so it would initialize some DB. After that, I could run docker exec ...
to do stuff — pg_restore
or something (can’t remember exactly). But it hit me with a bunch of invalid or not-found key errors (sorry, that's from memory — it was like 2 AM, so I couldn’t be bothered to save it).
2.2 I was like, cool, I guess I’ll try to recover the whole Postgres DB instead (I’m not familiar with SQL-type DBs, so pardon me if the wording is weird). So again, I ran docker compose up -d database
to spin up the DB and generate default configs and whatnot. And you guessed it — didn’t work either. There was some error related to an unknown locale or something, because my system uses en_CA
, while the container was using en_US
.
P.S. I guess to answer your question: no, I wasn’t importing anything before running docker compose up -d database
. That command essentially creates the coder
DB by default — hence the error about a duplicated DB and the container exiting.
3. This attempt was me trying to use pg_upgrade
, and oh boy, that was one hell of a headache.Postgres 16 is natively available in Noble (Ubuntu 24), so it was pretty easy to install.
As for Postgres 13 — it doesn’t have a candidate package for Noble, so I had to install it via the Postgres repo (again, I forgot the exact steps, but I managed to install it).
The result was pretty much the same as in section 2 — a whole bunch of unknown/invalid key errors, locale issues, and
coder
couldn’t auth users in the coder
table because the password had a different hash type or something.
This issue can definitely be replicated with old version of coder v2.7+ attempt to migrated to db (postgres16) on coder v2.20, I hope future coder will be easier to upgrade/migrate?
For me personally, I give up🤣 only a few ppl use coder on my sv so it'll be easy to create new workspace and reconfig them all again, not much work so I guess i'll be fine