When dockerizing your application under macOS Big Sur, you may encounter a situation where Docker fails to boot specific container that has port
80 assigned on the host machine. This happens because Big Sur comes with Apache 2.4 being preinstalled by default.
This article shows two methods on how to fix the issue.
Just use a different port. 🙈 Yes, I'm not kidding. Instead of:
ports: - 80:80
docker-compose.yml specify other port that is available:
ports: - 81:80
and finally run
docker-compose up -d.
This will indeed bypass port
80 being taken but you have to admit that this is a naive solution and I am pretty sure you are here for more robust approach.
We have to do two things:
- Stop Apache Server
- Prevent it from running again as soon as you restart macOS Big Sur
To stop it, open your favourite terminal application and type:
sudo apachectl stop
This will put Apache HTTP Server down.
To prevent it from auto-starting type:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
-w argument is the key to prevent the job from being loaded after macOS restarts.
This is it. I hope you will find this short article useful. Originally I have asked this question on StackOverflow and managed to answer it by myself. If this solution solved your problem, feel free to upvote both the question as well as the answer.
If you want to explore other articles I have tagged with "Docker", check them here.