Install Twenty using Docker on Macbook
Hello
I would like to install Twenty on my laptop (Mac) for local use.
I never used Docker, but I already setup some "old style" servers.
So I installed Docker Desktop and I pulled the three main images: server, front and postgres.
When I launch the server, I have the following error:
Error: connect ECONNREFUSED 127.0.0.1:5432
Obviously it is normal, as I did not setup any user/pwd for postgres.
I saw that I need to create a ".env" config file, but I don't know where I put this file in Docker desktop.
Could you help me?
Thanks a lot
51 Replies
Et Bravo @charles pour cet outil, sounds awesome
OK nevermind, I installed using yarn and it works.
Sorry about the slow response!
Sounds good 🙂
(Your .env file needed to be created in your twenty-server folder, it is not specific to docker)
No problem, I'm not used to play with docker and I did not find this folder. Yarn was easier with my skills 🙂
perfect!
we started with Docker but figured out it was easier for everybody to use yarn directly
Because I need graphql, I try to go using docker.
I propose to update the documentation after that 🙂
Here is what I used:
Launch database with a port bidding to be able to backup
run --name twenty-postgres -e POSTGRES_USER=twenty -e ALLOW_EMPTY_PASSWORD=yes -p 5432:5432 -d twentycrm/twenty-postgres:latest
Is it a good thing to use ALLOW_EMPTY_PASSWORD or do I need to setup a password here?
I setup ~/twenty/.env file:
After, I launch the server :
docker run --env-file ~twenty/.env --name twenty-server -d twentycrm/twenty-server
But I get an error here:
I suspect I'm not using .env the right way. Any idea how to proceed?
ok, it almost works
compose.yaml
.env file:
and launch with:
docker-compose up -d
you should have one .env in twenty-server and one .env in twenty-front (from the docs Step 2: https://docs.twenty.com/start/local-setup/docker-setup)
Welcome | Twenty - Documentation
Twenty is a CRM designed to fit your unique business needs.
also, do not use twenty as your container postgres user, it needs to stay "postgres"
while the container is initializing (make sure to drop the data so the init.sql script is indeed executed), it will create the "twenty" super user by itself
Erk.
Ok I ve done a docker-compose down and restarted with postgres instead of twenty and I get in twenty-postgres log:
I'll try a clean install.
yes, make sure that your container postgres user (the one used to boot the postgres container is "postgres")
twenty user should be created later during the docker boot while running the init.sql script
@iero let's discuss here
make sure to drop your twenty-postgres container + the associated volumes
Then make sure to provide "postgres" as the default POSTGRES_USER when you run your docker container
Once done, could you paste your docker logs here?
OK, ti drop the container, I just need to do
you also need to drop the volumes
what do you have in docker volumes?
OK, I removed all containers and volumes
I just have those images
the first one is from the git and others from the compose.yaml above
Here is my .env
where is your .env located?
Actually, I looked at your docker-compose, it should work :p
could you up your docker-compose?
what are the logs of twenty-postgres
I have put here:
`
I launch
what are the logs of twenty-twenty-db-1 ?
2024-02-13 17:04:14 2024-02-13 16:04:14.551 GMT [154] FATAL: password authentication failed for user "twenty"
this is not normal
how does your postgres container know about "twenty" user?
Indeed that is why I'm lost 🙂
Because it was here before and he kept it somewhere ?
is the compose.yml posted higher in the discussion still up-to-date?
yes
could you do
docker volume ls
?
something I noticed is that I use 'POSTGRESQL_PASSWORD' in the yaml file and not POSTGRES_PASSWORD be cause he asks me to set a password
(i'm trying to replicate)
ok, your postgres container can actually be fine
could you ssh into your postgres container
and run: psql -U twenty default
I think that the server ask for the user twenty:
yes, agree! but let's first make sure that your postgres is fine, then we can move to the server
psql -U twenty default ==> it should ask you a password, which is "twenty"
how do I ssh to the container ?
if you are using Docker for Mac, click on your container and go to "Terminal" tab
if you are not:
docker exec -it {containerId} sh
yes I use docker desktop on mac
I'm in:
great
so you are fine
let's move to the server container
PG_DATABASE_URL=postgres://twenty:PWD1@twenty-db:5432/default
make sure that PWD1 is actually "twenty"
OK, I used another custom pwd
ok, it might be it
If you are hosting for production, you might want to change this password 😉 (actually you must :D)
you want to update the password in .env file ?
yes 🙂
then, docker compose stop, then up
then, open a terminal in your twenty-server container
and you can type "env" to make sure your env variables are properly set
if it looks good,
yarn database:reset
and I would be interested to see the outputI have in the .env:
looks great!
(you don't need POSTGRES_USER and POSTGRES_PASSWORD here, the server only cares about PG_DATABASE_URL)
OK, I remove the lines and I restart
no log yet, still running
no error in db container, nothing in server and ready in front
Let's go with
yarn database:reset
in server ?
yes
Sounds good:
Looks great!
I don't see any error
All good?
I try to connect, fingers crossed
All good!
Merci beaucoup for taking the time to help me on this setup!
For the future, how do I update the system?
I do docker-compose pull and be sure to backup using psql_dump before?
I started to play with the API before the crash and it is not very complex to refill the database with it if I have a good backup.
I just have to backup the datamodel somehow
Right now we don't have a bullet proof way of updating the database schema, we are likely to write about it on the twenty docs in the upcoming weeks
The idea we have is the following:
- you can update front and server code by pulling the latest images (so updating version in your docker-compose)
- then you need to update database core, metadata schema (regular typeorm migrations) + update your workspace schema (which is ruled by your metadata to model your own busienss). We are preparing a set of commands to do that, we are already trying them in production, they work pretty well but are not ready to use yet
I would say upgrading to the latest version is hard right now, should be OK in a few weeks and easy in a few months once we've figured out all the details
the good thing is that we design our cloud as if it was self hosted, so the tools we build for the cloud will work for self hosted versions 🙂
If you want to look in the code, the commands are:
- yarn typeorm:migrate (to migrate core and metadata)
- yarn command workspace:health (check that your workspace schema is healthy)
- yarn command workspace:sync-metadata (migrate it to the latest version)
Will share a bit more about these later
Great thanks Charles, I learned a lot today !
I will start to adapt the datamodel, fill the database and do backups. My data is mostly on Obsidian and PSQL db, so the API wil be great to do the transfer.
I will check regularly and wait for when you will be ready to be sure I do not break everything too soon 🙂
sound good! Happy that you can self host Twenty and play with it!
Just for the record, if I don't have the two lines here, I get this warning: