Database installation and configuration

To install the MySQL Docker image, perform the following steps:

  1.  Open a new Terminal window and launch the following command, setting the name of the image, the port, and the credentials:
$ docker run --name mysql_thorntail -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql  

After that, the MySQL image will be launched as a container.

  1. To verify this, you can launch the $ docker ps -a command, which gives you a list of the containers created and their relative statuses. The status must be up.
  2. You can also check the container logs, in order to retrieve information about the MySQL status. Launch the following command:
$ docker logs   -f 6f1f54a5b932 

The 6f1f54a5b932 is the container ID. You should see the following information:

[System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.11' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
  1. Now, it's time to connect to the container, in order to manage it. Launch the following command:
$ docker exec   -it 6f1f54a5b932 bash 

The 6f1f54a5b932 is the container ID.

  1. Now, log in to the MySQL with the following command:
$ mysql -u   root -p   
  1. Set the password that's required (in our case, root). Now, you will be able to interact with the database server:
Welcome to the   MySQL monitor.  Commands end with ; or g.   

Your MySQL   connection id is 18   

Server   version: 8.0.11 MySQL Community Server - GPL
  1. Let's create the database that's needed for our microservice and select it for use, as follows:
$ CREATE DATABASE   football_managers_registry;   

$ use   football_managers_registry;   
  1. You can create the table in the container, as showing below, or delegate it to the source code implementation of your microservice. The first one is an easy but poor approach to use only in development environment:
CREATE TABLE   FOOTBALL_MANAGER(
ID SERIAL PRIMARY KEY NOT NULL,
NAME VARCHAR(50) NOT NULL,
SURNAME VARCHAR(50) NOT NULL,
AGE INT NOT NULL,
NICKNAME VARCHAR(50) NOT NULL
);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset