[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Have fun using docker commands with Makefile!

Fukuryu Ramen Watachi Main Branch (Honmachi, Osaka City)

Hello!
My name is Hide, the ramen king of Beyond Osaka Office.
This is my first post so I'm really nervous (sweat)

The impetus for writing this article was when I was job hunting.
When I was looking for a job, I had set up a development environment using Vagrant to create a portfolio, but
the PC specs were bad...it was extremely slow...it was the worst possible environment.
I found out about the existence of Docker, which is now popular on the Internet and SNS, and tried preparing it, but
what I really felt at that time was... ``Docker commands are really long and tedious...'' (TДT)
It's a shame because it works very smoothly...

When I enter various options, it becomes more than 20 characters, and it's very tedious to keep typing them every time.And
when the command is this long, I often make typos, which makes me twice as frustrated.
Everyone reading this has probably had the same experience ( ・`ω・´) Kiri

So let's take a look at how you can run docker commands with just a few characters!

 

What is docker?

 

First of all, do you know what docker is?

 

“It must be about container technology! ”
“It’s the whale one!
” ` `It works very lightweight, right? ”

All of the above are correct.

 

Docker is an extremely lightweight platform that uses container virtualization technology
to run programs quickly.
I don't think you can understand from this alone, so let's take a closer look m9(´∀`●) It's so good!!

 

 

Difference between hypervisor virtualization and container virtualization

 

 

There are two virtualization technologies that are often compared when explaining docker.
They are hypervisor virtualization and container virtualization, and Docker uses the latter virtualization.

 

First, we need to explain the difference between the two: hypervisor and docker engine.

 

 

hypervisor

 

 

A hypervisor works between the host OS and a VM (virtual machine),
emulating and controlling hardware such as the CPU and memory used by the VM.

With this, you can create multiple guest OSs of your choice on the host OS, and
the host OS and guest OS are isolated.

 

However, using multiple OSs means using multiple kernels, which
creates overhead and increases processing time, making it time-consuming to start and create VMs.

 

 

Docker Engine

 

Docker Engine controls the creation, startup, termination, deletion, etc. of docker.
You can use it by installing a resident Docker client such as Docker Desktop.

 

Unlike a hypervisor, Docker Engine does not create a guest OS and
shares the kernel with the host OS, so it has less overhead and is extremely fast and lightweight.

 

Although docker seems to have many advantages, one of its disadvantages is that the commands are very long.
Specifically, I sometimes type long commands like the one below....

docker-compose exec db bash -c 'mysql -u root -psecret'

 

 

What is Make tool?

 


This Make tool frees you from the docker commands that sometimes require such long commands.

 

As for how easy it is...

docker-compose exec db bash -c 'mysql -u root -psecret'

This command

 

 

make mysql

You can run it with just this command ヽ(´∀`*)ノ

 

This make tool was originally
a tool that allows you to easily build programs written in compiled programming languages ​​such as C and C++.
But you can also use it to abbreviate commands as shown above! !

 

Now, let's install it! !

 

 

 

Install Make Tool

⚠For Mac users, it is installed in the terminal by default, so for Windows users, please take a look.

 

 

 

 

 

Install from official installer

 

 

 

 

 

Click Setup under [Complete package, except sources] to install the installer.

 

 

 

 

 

 

 

Click [Next] and install according to the installer instructions.

 

Set up your Windows environment so that Make can be used anywhere

 

 

 

 

Go to Control Panel ⇛ System and Security ⇛ System and click [Advanced System Settings]

 

 

 

 

 

 

 

 

 

 

Click [Environment Variables...].

It is up to you to choose whether to set the settings as user environment variables or system environment variables.
If “Path” is already set in the variable list, please refer to ①. If it is not set, please refer to ②.

 

① Add to “Path” variable

 

 

 

 

 

 

 

 

Select “Path” from the variable list and click Edit.

 

 

 

 

 

 

 

 

 

Double-click the blank field, paste the absolute path below, and press the [OK] button to complete the setup!

C:\Program Files (x86)\GnuWin32\bin

 

② Add a new “Path” variable

 

 

 

Click [New], enter the following variable name and variable value as shown in the image, and
press the [OK] button to complete the setup!

 

 

 

After typing "make" in Power shell, if it looks like the following, the setup is complete!

PS C:\Users\beyond_tokuhara>make make: *** No target specified and makefile not found. Aborted.

 

 

 

What is Makefile?

Now you can install Make.
However, you cannot omit the docker command just by installing it.
You need to create a Makefile to omit that.


is a file that describes rules
for compiling, managing dependencies, etc. executes processing based on the rules.
Now, let's take a look at how to write it!

 

The description method is very simple.
You can write it in the following 4 steps! !

① Input the arguments to be set in the make command.
② Perform a line break.
③For Windows users, press the Tab key; for Mac users, press the → | key.
④Write the docker command.

 

mysql: docker-compose exec db bash -c 'mysql -u root -psecret'

 

 

⚠If the file is UTF-8 and has a BOM, the following error will occur if you open a space and run it.

please press the Tab key to create a space instead of the space key

 

make mysql makefile:5: *** Missing separator. Aborted.

 

 

Enter the Make command

Now that everything is ready, let's enter the command!

If it looks like the following, it will be a success ヽ(*·ᗜ·)ノヽ(·ᗜ·* )ノ High touch!

PS C:\Users\beyond_tokuhara>make mysql docker-compose exec db bash -c 'mysql -u root -psecret' Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.0 .21 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>

 

⚠Notes
- Omitting the docker command cannot be executed if there is no Makfile in the current directory.

・If you specify it with make -f, you can use the specified Makfile anywhere, but

if you run the Make command in a directory above the directory where docker-compose.yml and docker-compose.yaml are located, Please note that if you do so, the following error will occur.

PS C:\Users>make -f \Users\beyond_tokuhara\Makefile sql docker-compose exec db bash -c 'mysql -u root -psecret' ERROR: Can't find a suitable configuration file in this directory or any parent. Are you in the right directory? Supported filenames: docker-compose.yml, docker-compose.yaml make: *** [sql] Error 1

 

summary

What do you think?
So easy!
And I think I was able to execute the docker command with just a few characters (-`ω-)Wow!
Also, you can also play around with artisan commands by doing the following!

seed: docker-compose exec app php artisan db:seed

Makefiles are very convenient compared to aliases because they are less dependent on the environment and
can be used by immediately sharing files.
By all means, everyone, please enjoy a comfortable Docker life with Makefile.
Thank you for reading the article!

If you found this article helpful , please give it a like!
0
Loading...
0 votes, average: 0.00 / 10
17,176
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Hide@Infrastructure Engineer

It all started with a very interesting interview.
A mid-career employee of the System Solutions Department in Osaka.My
job is to build and operate servers and clouds!
I have the qualifications of LPIC1, AWS SAA, and OCI Architect Associate.

Actually, I love ramen and
have investigated over 100 stores in Osaka (。-∀-) I'm striving to become the Ramen King of Nibi Beyond
!

I'm also on Twitter, so please follow me (´∇`)
Click on the Twitter mark on the right corner! !