For various reasons (want specific version matching production environment, custom config etc) we are running our own Postgres and other servers via Docker in our CircleCI builds.
Despite the fact I did not request them in my circle.yml it seems that CircleCI starts up some services including Postgres and Mongodb by default.
I previously sought advice about this here and was advised to sudo service postgresql stop before trying to start my docker containers
This works most of the time but some percentage of the time the container fails to start with:
$ docker run -d --name postgres -p 5432:5432 postgres:latest
b3718197824603663612db13f9f1216d298bb4355f9ea332305aa3a7556a052a
Error response from daemon: Cannot start container b3718197824603663612db13f9f1216d298bb4355f9ea332305aa3a7556a052a: failed to create endpoint postgres on network bridge: listen tcp 0.0.0.0:5432: bind: address already in use
docker run -d --name postgres -p 5432:5432 postgres:latest
returned exit code 1
I thought… well maybe the port has not been completely freed yet, so I added a step, after the shutdown but before starting my container, that runs a bash script with a wait loop using netcat polling to check that the port is free.
This still fails sometimes with same error, after netcat has reported that the port is unoccupied. So now I suspect that the default postgres service is being restarted automatically and I effectively have a race condition to start my container before the system restarts the clashing service.
Same issue here. Although I stop postgresql service in pre dependencies and check that port is free with netstat, I get randomly the “bind: address already in use” issue with “docker-compose up”…
Also stuck with trying to get rid of the mongod process. Have tried killing it in just about every section of circle.yml, killing it multiple times, etc.
Now using this… appears to work for now, hopefully it will last longer than last workaround
- |
echo manual | sudo tee /etc/init/postgresql.override
while sudo lsof -Pi :5432 -sTCP:LISTEN -t; do
sudo service postgresql stop;
sleep 1;
done
make run-test
Have you tried 2.0? It gives you full control over the build environment so only services that you define end up running. This will be the best long term strategy.