Rails 6: Running on Docker with PHPMyAdmin
One day, I was using my Windows computer. Since the arriving of WSL 2 I wanted to play around with a Rails application. Just for the fun of practicing my Docker skills. The only big requirement for me? Use the Alpine Linux image, well known for the small image size they generate.
After a couple of hours of pain and suffering, I made it. My docker containers were working as expected and it was ready for work. Here, I present all the files and workarounds that I used.
đł Dockerfile
First. I created the Dockerfile
for the Ruby container. The route was .docker/Dockerfile
Do you see that tzdata
library? That was giving me errors when I tried bundle install. In short, I just wanted to install all my dependencies without any issues. Inside the container, the app will be located in the /app folder and it comes with the MySQL libraries for a DB integration.
Plus, I added nodejs
and yarn
as Alpine Linux libraries, we will need them as tools for local development use, specially since Rails relies on Webpacker for frontend development.
đŚ Docker compose
After that, we can create our docker-compose.yml
file. For this case, we are using a Ruby + MySQL 8.0 + PHPMyAdmin combo. Probably you are wondering, why PHPMyAdmin? Thatâs because I donât have any SQL UI tool in my Linux computer and I donât want to use the command line right now.
In the PHPMyAdmin container we need the root password, because we want to execute âpowerfulâ operations over our databases.
The dbdocker
and dbdocker_init
are extra folders that you can add to your project if you want to execute extra commands into your MySQL container. Remember once you added it to ignore all the content of dbdocker
, where the database files will remain. Itâs a good practice to create an empty .gitkeep
or .keep
file in the folder and then ignoring it. Here is the rule that Iâd use in my .gitignore
Remember that you can use a .env file and then add
env_file: - .env
to your docker compose file (removing the environment section per container first), if you donât want to commit your env values or if you change them often.