[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”

LAMP environment configured with docker containers ~ Beginners edition ~

Hello.
I'm Mandai, in charge of Wild on the development team.

A docker container is originally not something that runs completely in one docker container, but
multiple docker containers that work together to run a single service.

First, I would like to create a web system where two docker containers within one server work together.

This article is Part 4 of the Docker introductory series that will help you understand the basics of Docker.
If you would like to read past Docker introductory series, please follow the links below.

 

This time's goal

This time, we will proceed with the goal of building a primitive LAMP configuration using docker.
To explain what a primitive LAMP configuration is, what I have in mind is:

  • One docker container running apache+PHP
  • One docker container running MySQL
  • Connect separate containers and function as if they were installed locally.
  • When viewed from outside the VM, it looks like a normal web system.

I'm imagining a situation like this.

By this

  • You can learn how to launch multiple containers (although it's not that great)
  • Learn how to connect containers
  • This suddenly makes me think that it might be okay to put containers on separate servers.

I think it would be nice to know something like that.

I think it would be a good idea to try installing it with wordpress and get it working.
This time as well, we will proceed with the work on Ubuntu in VirtualBox.

 

Prepare the necessary docker images

The docker image required this time is

  • MySQL docker image
  • apache + PHP docker image

There are two.
The former uses the official MySQL docker image , and the latter uses the official docker image with WordPress

Now, pull the MySQL docker image from docker hub and start the docker container.

vagrant@vagrant:~$ docker run --name mymysql -e MYSQL_ROOT_PASSWORD=[mysql password] -d mysql:latest Unable to find image 'mysql:latest' locally latest: Pulling from library/mysql 86e6c3163927: Pull complete 68f4b3625ea4: Pull complete 04f7e78a2c8a: Pull complete 1bade56c3b6b: Pull complete dd6387e14c18: Pull complete ca30c0626c9b: Pull complete 0dc5e226a795: Pull complete 6c164b0f04cb: Pull complete 5c74d058f7b5: Pull complete 0fd3b6e12567: Pull complete e8126a9d061e: Pull complete d17cffff8039: Pull complete 1924f4186d05: Pull complete 14961e5db73a: Pull complete Digest : sha256:16de02081c408c41361126aaa718f91693688d39a216a74ac8dab841db050228 Status: Downloaded newer image for mysql:latest 12cb7271b424e8043d7bb36484061f49331a87be2 5bcd415e4a9a481a6b33c53

Let's check if the docker container starts.

vagrant@vagrant:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 12cb7271b424 mysql:latest "/entrypoint.sh mysql" 3 seconds ago Up 3 seconds 3306/tcp mymysql

It's starting up fine.
Next, pull the docker image containing wordpress and start the docker container.

vagrant@vagrant:~$ docker run --name mywordpress --link mymysql:mysql -p 8080:80 -d wordpress Unable to find image 'wordpress:latest' locally latest: Pulling from library/wordpress 9482852a6953: Pull complete 81de90fd7f09: Pull complete 57ae0639bf23: Pull complete c4f7968ac19e: Pull complete d06608e0df69: Pull complete 7ab219b6a3ea: Pull complete 049be7b00a71: Pull complete 1ac57811ebb0: Pull complete 5f7f35d35a61: Pull complete e7ff06ab86e9: Pull complete 50cbe 3cba4bd: Pull complete ef9f3544f906: Pull complete 0544870563ee: Pull complete 6b7e8b5d0ef6: Pull complete 4fb33229649f : Pull complete d0cabc0feb31: Pull complete 6fb545ed9179: Pull complete 9e9f602b9253: Pull complete 8d3522c82327: Pull complete 26c9007116c8: Pull complete 19faf318b397: Pull complete 04c297e0e874: Pull complete 0b9e66c139d 3: Pull complete 52cddd72d1ca: Pull complete 19d7bfb3a2a7: Pull complete 15031c83aa88: Pull complete 9c3238040649: Pull complete 492d7fea8944: Pull complete 676505bb515e: Pull complete eea959e50c85: Pull complete 1029747e7634: Pull complete 155de5677313: Pull complete Digest: sha256:bfd7e102741d73cce4ec58b2d937586c670f31df 1c80aeaf4d5c525eb3c6ac06 Status: Downloaded newer image for wordpress:latest 8606df07f39f2a22dbdefd916b42c1747ca1df86f4a012620862c039d110887f

Once finished, check if the docker container is running.

vagrant@vagrant:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8606df07f39f wordpress "/entrypoint.sh apach" 3 seconds ago Up 3 seconds 0.0.0.0:8080->80/tcp mywordpress 12cb7271b424 mysql:latest "/entrypoint. sh mysql" 2 minutes ago Up 2 minutes 3306/tcp mymysql

The installation of the necessary items is now complete.
The wordpress docker image does not include MySQL, but as I read the explanation on docker hub

  • If you install it by adding the option "--link mymysql:mysql", it seems to be set up as a MySQL container using a docker container named mymysql.
  • The default value of WORDPRESS_DB_HOST is unspecified because it uses the linked mysql container.
  • WORDPRESS_DB_USER is unspecified because the mymysql container will be accessed as the root user for the time being (change recommended).
  • If WORDPRESS_DB_PASSWORD is not specified, the MYSQL_ROOT_PASSWORD variable that was set when starting the connected mysql container will be obtained from the mysql container, so there is no need to specify it again (recommended).
  • The default value of WORDPRESS_DB_NAME is wordpress. If you prefer another DB name, please state so.

If you control this area, it seems that you can connect to the DB across containers without any problems.

 

Set up wordpress from your browser

Let's look at the wordpress installation screen again from the browser.
Since I am running docker on Ubuntu on the VM, I wrote the following in the Vagrantfile to port forward port 18080 on the host PC to port 8080 on the VM.

config.vm.network "forwarded_port", guest: 8080, host: 18080

Port 8080 of the VM is forwarded to port 80 of the wordpress docker container, so 18080 is connected to port 80 of the docker container.

When I accessed http://localhost:18080/, a setup screen was displayed.

wordpress_installation_01

Select Japanese as the language and press Continue.

wordpress_installation_02
Enter the information required to log in

wordpress_installation_03

Completed. Oh, that's easy.

wordpress_installation_04

Next, a login form appears, so enter the username and password you entered earlier.

wordpress_installation_05

I arrived at the dashboard.

It was over in no time, but if you create a web service properly using rails etc., you can deploy it using the same pattern if you create a docker image by including git clone and rake commands in the Dockerfile. That's amazing.

Also, you can change the use of AWS RDS for the DB by simply specifying the IP address, and it is very easy to arrange things like placing an nginx docker container.
It all depends on how you link your docker containers.
That's it.

If you found this article helpful , please give it a like!
0
Loading...
0 votes, average: 0.00 / 10
1,550
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

Yoichi Bandai

My main job is developing web APIs for social games, but I'm also fortunate to be able to do a lot of other work, including marketing.
Furthermore, my portrait rights in Beyond are treated as CC0 by him.