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.

Copy to Clipboard

Download the Ubuntu docker image from the online repository.

Copy to Clipboard

List the Docker images installed on your system.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Start a new Ubuntu container using this Docker image.

Copy to Clipboard

Now, you are on the container command-line.

Copy to Clipboard

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.

Copy to Clipboard

Install the Apache service.

Copy to Clipboard

The system will request you to select a timezone.

Copy to Clipboard

In our example, we configured the timezone to America, São Paulo.

Copy to Clipboard

Install the MySQL service.

Copy to Clipboard

Edit the MySQL configuration file named mysqld.cnf.

Copy to Clipboard

Inside the configuration file, locate the following line.

Copy to Clipboard

Change this line value to 0.0.0.0.

Copy to Clipboard

Start the MySQL service manually inside the container.

Copy to Clipboard

Access the MySQL command-line.

Copy to Clipboard

Set a password for the MySQL root user.

Copy to Clipboard

In our example, the root user password was set to kamisama123.

Create a configuration file named supervisord.conf.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

On the root directory of the container, create a script named run.sh.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Configure the correct file permission.

Copy to Clipboard

Exit the container command-line.

Copy to Clipboard

Create a Docker image based on this container.

Copy to Clipboard

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.

Copy to Clipboard

Test your access to the Apache service.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Test your access to the MySQL service.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Congratulations! You have finished the creation of a Docker image offering multiple services.