DEV Community

Cover image for Docker and My Experiences
Alec
Alec

Posted on • Updated on

Docker and My Experiences

In 2022 I started using Docker. Prior to that I was using MAMP or doing development on VPS servers specifically set up for development testing. The initial configuration was a bit of a learning curve, but now that I'm over that hump... working with Docker has been amazing.

Basic Setup

I define projects and store them in GIT/BitBucket. Those contain docker-compose.yml files and .sh files to build my Docker environments, as well as all the actual web pages which are part of the project.

Pull from GIT. Run a couple .sh scripts to first build then start the Docker images and "boom", I have an ideal development environment. I could run docker commands in Terminal like docker-compose build and docker-compose up -d would work just as easy as the .sh files but I prefer the .SH files which I define with more intuitive names.

My Docker Images/Container

  • Nginx:1.22.0-alpine
  • MySQL 8.3
  • PHP 8.1-FPM
  • phpMyAdmin

Each use a "Volume" for data in the database, and another "Volume" for the web pages.

In 2022 we converted everything to PostgreSQL because AWS "serverless PostgreSQL" was so much cheaper than MySQL. That worked great but in 2023 we switched back to MySQL since AWS now offers that "serverless" as well. Utilizing docker-compose.yml switching between MySQL and PostgreSQL is only a few lines of code. Modifying the PHP for the SQL syntax changes was a much bigger job.

Likewise, with Docker it is extremely easy to slightly change the docker-compose.yml so you can test different versions of PHP, MySQL or Nginx.

Real Life Advantages with Docker

Over the last year I bought a new laptop (MacbookAir) to replace my older MacbookPro. Simple GIT PULL and .sh call and my Docker environment was identical and working perfectly. A few months later I bought an iMac and same situation. Now passing environment from new laptop to new iMac is as simple as a push and pull from GIT.

Even more importantly, the same Docker containers I work on are also used by other programmers in our company and there's never a concern that our environments are out-of-sync. Plus our company's DevOps tech uses a slightly modified docker-compose.yml for building final containers which are uploaded to AWS. They are small and instantiate quickly and with his setup more spin-up as needed based on demand.

This has worked so well that I've changed all my website development to use this GIT and Docker methodology.

Docker inside of Docker

So other developers could easily test Wizard's Toolkit, I created a simple Docker image that contains all the files necessary to generate an ideal Nginx/PHP/MySQL Docker environment.

Try to get your head around this. I have an image which you pull down, run a script that extracts all files from, then delete. Then run .sh file to build the perfect Docker development environment. All the PHP and web pages are in an easily accessible subfolder (which Docker calls a Volume), and puts the data in a subfolder (aka Volume).

This is a way to try out Wizard's Toolkit, the low-code PHP/SQL development library. For full disclosure, there is a small subscription fee to use Wizard's Toolkit on production servers. This method allows developers to test how easy and intuitive it is to build websites with Wizard's Toolkit on their local Docker environment.

Of course, there's nothing preventing anyone from pulling down the Docker environment then deleting the /WTK/ files and just use it as your ideal Nginx/PHP/MySQL or PostgreSQL environment.

Interested in Seeing for Yourself?

All technical details are in the Docker hub regarding what each of the 5 steps do:
https://hub.docker.com/r/proglabs/wizards-toolkit

After creating a new empty folder and cd'ing to it in Terminal, the 5 simple steps can be abbreviated to:

docker pull proglabs/wizards-toolkit

# when that finishes, start the container
docker run --name wtk_website -d proglabs/wizards-toolkit

# when that finishes, extract all files from this image into your folder
docker cp wtk_website:/wtkapp/. .

# when that finishes, to build and start container
./WTK.sh

# when that finishes, to create MySQL database, tables and insert data
./SETUP_MYSQL.sh
Enter fullscreen mode Exit fullscreen mode

Summary

If you haven't tried Docker yet, you should. If you do use Docker then maybe the "Docker inside Docker" method I outlined will help with one of your projects. Please let me know if anyone has a better method for this type of deployment.

Video showing above steps and WTK Starter Website

Thanks

Top comments (0)