(English) How to setup Docker container SQL Server 2017 for Liferay Development Environment

Ci spiace, ma questo articolo è disponibile soltanto in Inglese Americano. Per ragioni di convenienza del visitatore, il contenuto è mostrato sotto nella lingua alternativa. Puoi cliccare sul link per cambiare la lingua attiva.

When we start a new project using Liferay and the project involves the development of new entities, I suggest to set up your own local development environment as closely as possible to the customer’s development environment, particularly as regards the database.

In this article I will explain how to use Docker to setup the Microsoft SQL Server 2017 container for use with Liferay. I also recommend reading the article How to build a Docker Liferay 7.2 image with the Oracle Database support.

These instructions comprise the bare-minimum setup required for initialization of a Liferay instance. The instructions are targeted for an audience of experienced developers with little to medium experience of Docker and Liferay. The deployment described results in a per-developer SQL Server setup on your local development host that you can use for Liferay.

 

1. What are the requirements

Before proceeding with the Docker container setup, let’s see what the requirements are:

  • You need an account on Docker, which you can create from Docker – Signup;
  • You need to install or update Docker on your PC. Refer to this article for how to install Docker on Windows.

The docker versions on which I have successfully run the SQL Server Docker container are: 17.x, 18.x and 19.x. The version of Docker Engine (Community Edition) that I will refer to in this article is 19.03.1 (you can check version with command docker version). For more information regards SQL Server requirements you can read Quick Start: Run SQL Server container images with Docker.

What is shown in this article can be performed on Windows, Unix-like operating systems. In my case I use macOS. However, always refer to the documentation of Docker and SQL Server for what concerns the minimal requirements that the target system must have.

 

2. SQL Server Database Docker Image

The latest version available is SQL Server 2017, this release is the version supported by Liferay (you can see Liferay Digital Experience Platform 7.2 Compatibility Matrix). Official images for Microsoft SQL Server on Linux for Docker Engine available on Docker Hub.

The version of our interest is the latest version: SQL Server 2017. We then perform the pull with the following command.

 

 

Once the pull is done we could get more information on the image using the command docker images and docker inspect mcr.microsoft.com/mssql/server:2017-latest

 

3. How to starting SQL Server Database Server instance

To get a working SQL Server instance for use with Liferay, we need to:

  • Creating a Docker container for SQL Server
  • Setting up a database and login user specifically for Liferay

 

We start by deploying the Microsoft-supplied SQL Server image to a local developers host: It will take one or two minutes to initialize the database.

Docker manages several kinds of objects the two we are interested in here are the so-called docker image (a minimal linux operating system with Microsoft’s SQL Server installed); and a docker container, which is a virtual machine running an instance of that image.

The above command accomplishes both of these functions, fetching the image from Microsoft’s Docker Hub account to your local computer and starting that image it in a container.

The argument -p host-external-port:container-internal-port makes the container’s sql server port (which must be 1433) available on the specified host computer’s port.

Port 1433 is the default port for MS SQL Server. I explicitly specify the defaults in the commands below for those cases where you might want to expose several SQL Servers, each in their own container, each exposing a unique port on the host computer.

The -d flag causes docker to run the container in the background as a daemon process.

The –name sqlserver.local argument provides an optional name for the container; it is arbitrary but must be unique across your containers. It is merely for convenience.

The -h sqlserver.local argument provides an optional hostname for the container; it is arbitrary but must be unique across your containers. It is merely for convenience.

The argument -v mssql-data:/var/opt/mssql  creates an independent docker volume named mssql-data which associates the /var/opt/mssql  filesystem on the container to an external independent volume – think of it as a share that will be mounted. The Microsoft-supplied SQL Server image has been specifically configured to keep all its data in that filesystem.

Docker images have a default startup command built-in; the -e variable=value arguments set environment variables and are a way to indicate to the start-up program that we are in the process of setting up the Microsoft SQL Server instance.  They need only be run once  when initially setting up a container.

The SA_PASSWORD environment variable set the system administrator password. In this case the password set to: yourStrong(!)Password

Note that by default the hosts 1433 port is available on both on the external interface (its TCP/IP address) as well as the loop-back port (localhost). You can get information on our setup with the docker ps, docker volumes and docker container inspect commands.

 

Great 😉 We are almost there. At this point we have to create the database, the login, the user and assign the correct permissions for the user who must access the Liferay database. The SQL script shown below performs the above description.

 

To execute the script we can use the following command docker exec.

Now you can connect, from the host computer, to the containers’ SQL Server via sqlcmd as the liferay user as so:

Executing the query SELECT @@VERSION produces the output shown above. The query returns detail information about the SQL Server version. The images below show the setup of the connection to the Liferay database that we have just created. The tool used is Azure Data Studio.

 

Figure 1 - Setup connection to Liferay Database

Figure 1 – Setup connection to Liferay Database

 

Figure 2 - Database Workspace

Figure 2 – Database Workspace

 

4. The next step

In the next article (which will come soon), we will see How to create a Docker Liferay 7.2 image with support for the SQL Server 2017 database.

0 Condivisioni

Antonio Musarra

I began my journey into the world of computing from an Olivetti M24 PC (http://it.wikipedia.org/wiki/Olivetti_M24) bought by my father for his work. Day after day, quickly taking control until … Now doing business consulting for projects in the enterprise application development using web-oriented technologies such as J2EE, Web Services, ESB, TIBCO, PHP.

Potrebbero interessarti anche...