Chapter 6: PostgreSQL

@warplydesigned Nope. But well it did not hurt asking. I wanted to go the docker route so I can more easily migrate the project later on to the cloud.

@0xtim I am using the single container docker up as a daemon. Later on I would have changed to docker compose, but as of now I used the command presented in your book ā€žServer Side Swift with Vaporā€œ. I bought it recently and started with my own project but I on the basis of the bookā€™s examples.

By the way this is the output of docker ps:

Frank-Martin:Debug atrust$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
a7f9dbb7784e        postgres            "docker-entrypoint.sā€¦"   2 days ago          Up 2 days           0.0.0.0:5432->5432/tcp   postgres

And this is how I started it:

docker run --name postgres -e POSTGRES_DB=vapor -e POSTGRESS_USER=vapor -e POSTGRESS_PASSWORD=password -p 5432:5432 -d postgres

Hmm that looks all good. Have you tried restarting your machine? Apparently thatā€™s helped before

Guys, I finally got it to work. #yay - Seems that after I did ā€œvapor updateā€ I had Xcode opened and it asked me if I wanted to revert the code to the content it had, or accept the changes. So I did the wrong decision back then. As I tried to do the project anew I close Xcode before running ā€œvapor updateā€ and afterwards everything was running as expected.

Maybe some others have experienced the same issues and this might help. As they say, the problem sits in front of the computer.

Thx for your help. Keep up the good work.

1 Like

I had challenges with this too and I tried every thing above and was about to give up but I got it working. I had another Postgres instance running but could not see it with
lsof -i :5432

use
sudo lsof -i :5432

then you will see the process running if there is a non docker process running on port 5432 then use the following to kill it.

sudo kill <pid>
eg. sudo kill 50830

Next enter, docker restart postgres

This will restart your container

Next run your app in Xcode and you should be all set.

Also I recommend testing this with the included project files for chapter 6 in the final folder. I had tried a few things with my own version that had rendered it useless :slight_smile:

1 Like

@farmerdev Thank you for sharing your solution - much appreciated! :]