This chapter discusses the process of baking (i.e. creating) images for docker hub. It also gives a recipe for creating docker images. If you are interested only in installing RAP3, you do not need this chapter.
Docker images are baked when the Ampersand source code for RAP3 is ready to be deployed. This results in three files, to be stored on Docker hub:
RAP3 is deployed as shown in this picture
Knowing what needs to be done allows you to understand how we make Ampersand's docker images. If you just want to do it, follow the steps below. We assume that you are working on an Ubuntu machine with
bash as its command line interface.
First I checked that docker and docker-compose are installed on my computer:
sjo@lnx-hrl-202v:~$ which docker/usr/bin/dockersjo@lnx-hrl-202v:~$ which docker-compose/usr/bin/docker-compose
If you need to install docker, follow the instructions on https://docs.docker.com/engine/installation .
RAP is built on Ampersand and is compiled with Ampersand. For this reason, the RAP image builds on an Ampersand image. Run ./build.sh to build the initial ampersand container that serves as a base for the RAP3 application (or any other Ampersand application). This base images holds all required packages and the (at that moment) latest version of the ampersand compiler the workflow around this container can/should be improved since now the easiest way to rebuild is to remove the container (docker rmi ampersand:latest)
I cloned the docker files into a local directory by the following command:
sudo -igit clone https://github.com/AmpersandTarski/docker-ampersand/ /home/$(whoami)/docker-ampersandcd docker-ampersand/./build.sh
and sat back to watch an image being created. This takes over an hour. I left the session up and running, because stopping the session means that the docker build process stops. After coming back a day later, I verified that the image is present by running the same command again. That produced the following output:
Wolfram docker-ampersand # docker build -t ampersand:latest ampersandSending build context to Docker daemon 4.096 kBStep 1 : FROM php:7-apache---> 2720c02fc079Step 2 : ENV PATH /texlive/bin/x86_64-linux:$PATH---> Using cache---> 45d62477f5e2Step 3 : RUN apt-get update && apt-get install -y --no-install-recommends git graphviz wget xorriso && curl -sSL https://get.haskellstack.org/ | /bin/sh && rm -rf /var/lib/apt/lists/*---> Using cache---> e37542ec9301Step 4 : ENV TL_VERSION 2016-20160523---> Using cache---> f95346ded414Step 5 : ADD texlive.profile /tmp---> Using cache---> add9fd911c38Step 6 : RUN cd ~ && wget -q http://mirrors.ctan.org/systems/texlive/Images/texlive$TL_VERSION.iso && wget -qO- http://mirrors.ctan.org/systems/texlive/Images/texlive$TL_VERSION.iso.sha512 | sha512sum -c && osirrox -report_about NOTE -indev texlive$TL_VERSION.iso -extract / /usr/src/texlive && rm texlive$TL_VERSION.iso && /usr/src/texlive/install-tl -profile /tmp/texlive.profile && rm -rf /usr/src/texlive && rm /tmp/texlive.profile---> Using cache---> f0ebcd4cf50cStep 7 : RUN mkdir ~/git && cd ~/git && git clone --branch development https://github.com/AmpersandTarski/Ampersand---> Using cache---> 08643d5cce73Step 8 : RUN cd ~/git/Ampersand && stack setup && stack install --local-bin-path /usr/local/bin---> Using cache---> 636036e98214Step 9 : RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php --install-dir=/usr/local/bin --filename=composer && php -r "unlink('composer-setup.php');"---> Using cache---> e8648c6657f6Successfully built e8648c6657f6
When you build an image where nothing changes (as shown above), this takes virtually no time at all. However, if you run a fresh image from scratch, it takes a while. Should you want to close your SSH-session in which docker is running, that docker process will be killed. If you want to leave docker running in the background,
https://www.tecmint.com/keep-remote-ssh-sessions-running-after-disconnection/ will help. Best thing is to anticipate on it. However, if you didn't anticipate this, you can still send docker to the background by
^Z and give the
disown -h command. (The latter is however the least elegant way.)
I checked whether all images are built by the
docker images command:
sjo@lnx-hrl-202v:~/ampersand-models/RAP3$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEampersandtarski/ampersand-rap latest 636643166a78 2 hours ago 3.62GBampersandtarski/ampersand-prototype-db latest d267da36fb90 4 hours ago 395MBampersandtarski/ampersand-prototype texlive efd0dccd6b4b 6 hours ago 3.11GBphpmyadmin/phpmyadmin latest 200931982ab6 6 days ago 110MB
For this step, you need an account on docker-hub. Then Docker will simply push the generated images to docker hub by means of the push-command:
docker push ampersandtarski/ampersand-rapdocker push ampersandtarski/ampersand-prototype-dbdocker push ampersandtarski/ampersand-prototype
At this point the images are published and this chapter is done. However, it is good to discuss a few collateral issues: deployment, maintenance and security.
We are making three containers: one for the database, one for the RAP3 application, and one for PhpMyAdmin. Containers are built from images by the command
cd /home/ampersandadmin/docker-ampersanddocker-compose up -d
This command brings all three containers up and runs them in the background. For this to happen, the file
docker-compose.yml must be in the current directory.
I checked whether the containers are running by means of the
docker ps command.
Completion of this step allowed access to RAP3 from an arbitrary computer on the internet:
The database is accessible on port 8080:
docker-compose up command aggregates the output of each container. When the command exits, all containers are stopped. Running
docker-compose up -d starts the containers in the background and leaves them running.
To interfere with RAP3 as it is running, you need to get into the Rap3 container. It is not enough just being on the server, because all the data is in the container (rather than directly on the server). To go into the Rap3 container, use the command
docker exec -ti dockerampersand_rap3_1 /bin/bash
To inspect and change the local settings, you need the file
localsettings.php on directory
~/git/Ampersand-models/RAP3/include. This step requires section 5 to be finished successfully. This file contains comments that guide you to use the correct settings in a development situation and in a production situation. Read the file and follow the instructions it contains, especially when making the transition from development to production.
In the source code of RAP3, in the file SIAM_importer.adl:
disable "RAP3_LoginForDevelopment.ifc", to prevent users from seeing
Is there anything we must alter in localsettings.php before going live?
This is decribed in the file