Would you like to learn how to run multiple services inside a Docker container? In this tutorial, we are going to show you all the steps required to run multiple services inside a Docker container on a computer running Ubuntu Linux.
• Ubuntu 18.04
• Ubuntu 19.10
• Docker 19.03.6
In our example, a single Docker container will run the MySQL service and the Apache service.
The Apache service will listen on the TCP port 80.
The MySQL service will listen on the TCP port 3306.
Tutorial Docker – Container running multiple services
Install the Docker service.
Download the Ubuntu docker image from the online repository.
List the Docker images installed on your system.
Here is the command output:
Start a new Ubuntu container using this Docker image.
Now, you are on the container command-line.
In our example, the Ubuntu image was used to start a new container.
In our example, the container ID is 62f9adcafb62.
In our example, the container was named MYCONTAINER.
Install the list of required packages.
Install the Apache service.
The system will request you to select a timezone.
In our example, we configured the timezone to America, São Paulo.
Install the MySQL service.
Edit the MySQL configuration file named mysqld.cnf.
Inside the configuration file, locate the following line.
Change this line value to 0.0.0.0.
Start the MySQL service manually inside the container.
Access the MySQL command-line.
Set a password for the MySQL root user.
In our example, the root user password was set to kamisama123.
Create a configuration file named supervisord.conf.
Here is the file content.
On the root directory of the container, create a script named run.sh.
Here is the file content.
Configure the correct file permission.
Exit the container command-line.
Create a Docker image based on this container.
In our example, we created a Docker image named MYIMAGE based on the container named MYCONTAINER.
Start a new Docker container using the image created.
Test your access to the Apache service.
Here is the command output:
Test your access to the MySQL service.
Here is the command output:
Congratulations! You have finished the creation of a Docker image offering multiple services.