15. Running the Website from a Container

UNDER DEVELOPMENT

In this chapter, you will learn how to set up an application consisting of a gateway that lets tasks run in the Docker containers you created in the previous chapter. In chapter 15, we will extend the functionality with a web interface, for which we will use the Julia package Bukdu.jl. This choice is not entirely voluntary. Originally we thought to use Genie.jl as Julia Web Framework, but we discovered that Distributed Computing was a problem.

                web
                 ⇵
              gateway
         ________⇵________
         ⇵               ⇵
     test_sshd2      test_sshd
     (GeneralLedger)  AppliAR

Fig 1: The three containers that make up the application

Contents

Activity 15.1: Create the Gateway Container

The Gateway container runs the software where actors perform different tasks on the other Docker containers. For communication between the different containers with Julia, the condition is that they have passwordless SSH connections.

With the Rocket.jl package you can set up an infrastructure based on actors. You can communicate with actors utilizing messages.

Prerequisites
  • Your system has Ubuntu 20.04 that runs on an Intel x86 processor.
  • You have installed Docker.
  • You have performed the activities and exercise of chapter 13.
  • The Docker image eg_sshd exists.

In this activity you will:

  1. Create the gateway container.
  2. SSH enable the container.
  3. Install Julia.
  4. Add the packages AppliSales, AppliAR, AppliGeneralLedger, Rocket, DataFrames, and Query.
  5. SSH enable the container.
  6. Create SSH keys for the container.
  7. Add the files testwithactors.jl and actors.jl
Step 1: Create the gateway container

You create the container gateway from the image eg_sshd.

StepActionComment
1$ docker run -d -p 2224:22 -p 8004:8000 --name gateway eg_sshdCreate a container gateway.
2$ docker exec -it gateway bashEnter the container
3# adduser rob
4# apt-get updateDownload package information
5# apt-get install sudoYou act as root when you precede your commands with sudo. It is not installed yet in this minimized container.
6# usermod -aG sudo robGive user administrator rights.
7Ctrl-DLeave the container.
Step 2: SSH enable the container

You copy the public key you created in activity 13.1 to the container for passwordless authentication.

StepActionComment
1$ docker stop test_sshd test_sshd2 gatewayStop the containers.
2$ docker start test_sshd test_sshd2 gatewayStart the containers.
3$ docker psCheck whether the containers are running.
4$ docker inspect gateway | grep "IPAddress"Find internal IP address of the container:$\\$172.17.0.4
5$ ssh-copy-id rob@172.17.0.4Copy id to container for passwordless login.

You get the next message:

The authenticity of host '172.17.0.4 (172.17.0.4)' can't be established.
ECDSA key fingerprint is SHA256:0qEmNoH8hb1OC73Hcecf4iY44vKAnLYOc6jNsdkkM2U.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Type yes and enter your password.

Step 3: Install Julia
StepActionComment
1$ docker start test_sshd test_sshd2 gatewayEnsure all containers are running.
2$ docker cp ~/Downloads/julia-1.5.3-linux-x86_64.tar.gz gateway:/home/robCopy the downloaded file to the container.
3$ docker exec -it gateway bashEnter the container.
4# su robSwitch to user rob.
5$ cd ~Go to home directory of the user.
6$ sudo mkdir juliaCreate folder julia. OS asks for yur password.
7$ sudo mv julia-1.5.3-linux-x86_64.tar.gz juliaMove file to folder.
8$ cd juliaEnter the folder
9$ sudo tar -zxvf julia-1.5.3-linux-x86_64.tar.gzExtract the file.
10$ cd julia-1.5.3/bin/We will test Julia.
11$ ./juliaStart Julia. You get the next response:
12julia> Ctrl-DLeave Julia.
13cd ~To home directory.
14$ sudo ln -s /home/rob/julia/julia-1.5.3/bin/julia /usr/local/bin/juliaCreate link.
15$ juliaStart Julia.
16julia> Ctrl-DLeave Julia.
17$ Ctrl-DReturn to root.
18# Ctrl-DLeave container.

Activity 15.2: Restart the Containers and Enable SSH for the Container gateway

Prerequisites:

In this activity you will:

  1. Start the containers and check their Docker internal IP-address.
  2. Use SSH to Connect from gateway to test_sshd and test_sshd 2 and install the packages.

Step 1: Start the containers and check their Docker internal IP-address
StepActionComment
2$ docker restart test_sshd test_sshd2 gatewayStart the containers.
3$ docker psCheck whether the containers are running.
4$ docker inspect -f "{{ .NetworkSettings.IPAddress }}" test_sshde.g. 172.17.0.2
5$ docker inspect -f "{{ .NetworkSettings.IPAddress }}" test_sshd2e.g. 172.17.0.3
6$ docker inspect -f "{{ .NetworkSettings.IPAddress }}" gatewaye.g. 172.17.0.4
Step 2: Use SSH to Connect from gateway to test_sshd and test_sshd 2 and install the packages
StepActionComment
1$ ssh rob@172.17.0.4
2$ sudo apt-get update
3$ sudo apt-get install openssh-clientInstall ssh client in container.
4$ ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"Generate the key.
8$ ssh-copy-id rob@172.17.0.2Copy id to container test_sshd for passwordless login.
9$ ssh-copy-id rob@172.17.0.3Copy id to container test_sshd2 for passwordless login.
10$ ssh rob@172.17.0.2Check paswordless login.
11$ Ctrl-DLeave container.
12$ ssh rob@172.17.0.3Check paswordless login.
13$ Ctrl-DLeave container.
14$ juliaStart Julia in the container gateway.
15julia> ]Activate the package manager.
16pkg> add AppliSales AppliGeneralLedger Rocket DataFrames QueryAdd the packages.
17pkg> add https://github.com/rbontekoe/AppliAR.jl
18pkg> precompilePrecompile all the project dependencies.
19pkg> instantiateDownloads all the dependencies for the project.
20pkg> <Backspace>Leave package manager.
21julia> Ctrl-DLeave Julia.
22$ ssh rob@172.17.0.2Enter the container test_sshd.
23$ juliaStart Julia in the container.
24julia> ]Activate the package manager.
25pkg> add AppliSales AppliGeneralLedger AppliAR DataFrames QueryAdd the packages.
26pkg> add https://github.com/rbontekoe/AppliAR.jl
27pkg> precompilePrecompile all the project dependencies.
28pkg> instantiateDownloads all the dependencies for the project.
29pkg> <Backspace>Leave package manager.
30julia> Ctrl-DLeave Julia.
31$ Ctrl-DLeave the container test_ssh.
32$ ssh rob@172.17.0.3Enter the container test_sshd2.
33Repeat the steps 22 untill 31 for the container test_sshd2 (172.17.0.3)