Installing Coco in Docker
In this chapter we give an example on how to run Coco, terminal only interaction, in Docker.
Prerequisites
- A Linux machine, in this example Debian,
- Docker (latest version, but any stable version should work fine).
Installation of Docker
Before installing Coco we need Docker to be installed. To check if Docker is running on your machine, type:
$ docker --version
Skip the following step if Docker is already installed on your machine.
Installation from the Debian repository
A standard Debian distribution contains already a Docker package. It is usually called docker
or docker.io
. To install it, run:
$ sudo apt-get install docker.io
Installation from the Docker repository
If you need the newest version of Docker, you can use the Docker repository instead. The following procedure to install Docker is mostly the same for all Linux based machines. For more information, see the Docker documentation.
- Update the
apt
package index:$ sudo apt-get update
- Install packages to allow
apt
to use a repository over HTTPS:$ sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
- Add Docker's official GPG key:
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
- Use the following command to set up the stable repository:
$ sudo add-apt-respostiory \ "deb [arch=amd64] https://download.docker.com/linux/debian \ $(lsb_release -cs) \ stable"
- Update the
apt
package index:$ sudo apt-get update
- Install the latest version of Docker CE and
containerd
:$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Verification of the installation
Now verify that your user account has the right to run Docker containers. On most UNIX® systems, a user must be in the docker
group. To verify this, use the id
command, which prints the current groups a user is in. If you are not a member of docker
, run:
$ sudo adduser
<own account> docker
But afterwards it is usually necessary to log in again in order to make the group change visible.
To verify that Docker CE is installed correctly, run the hello-world
image:
$ docker run hello-world
To remove the hello-world
image, first run:
$ docker ps -a
The output should be a list of containers, with name, status, and more. It should contain one header line and one line for the hello-world
image. In the first column, there is the container ID of the hello-world
image. Run:
$ docker rm
<container_id>
Installation of Coco in a Docker container
- Create an empty directory. We will refer to it as work directory.
- Download a Coco package to the work directory. It must be a file that ends in
.run
, likeSquishCocoSetup_5.0.0_Linux_x86_64.run
. - In the work directory, create a file named
Dockerfile
, with the following content:# Select base image FROM debian # Install packages for your project RUN apt-get update && apt-get upgrade -y && apt-get install -y libgtk2.0-dev # Set "secret" as root password RUN echo "root:secret" | chpasswd # Define a user RUN useradd -ms /bin/bash myapp USER myapp WORKDIR /home/myapp # Copy the Coco installer to the work directory COPY SquishCocoSetup*.run .
For an actual project, the content of the file must be adapted. In this example, it does the following:
- Loads an image from the Docker Hub website. In this case it is the most recent Debian image, but any Linux image should work.
- Installs some packages. In a real use case, these would be the prerequisites of the software project for which code coverage should be measured.
The installation commands that are given here obviously only work on a Debian or Debian-like system, like Ubuntu.
- Sets a root password that is later needed by the Coco installer, which runs from a user account.
- Creates a user account.
- Copies the Coco installer into the container. It will be located in the home directory of the user
myapp
.The wildcard pattern
SquishCocoSetup*.run
matches the name of any Coco installer package, independent of the version number.
- In the work directory, run the command:
$ docker build -t squishcoco .
Docker will then create an image with the name
squishcoco
. - To run the image, execute the command:
$ docker run -it --name runner squishcoco
Then a container named
runner
will be created and started. - You will now see the command prompt of the container, no longer that of your operating system. You are now in the home directory of the user
myapp
.This directory also contains a copy of the Coco installer package. You can run it with a command like:
myapp@a6e8af:~$ bash SquishCocoSetup_5.0.0_Linux_x86_64.run
The installer will then let you choose between different installation modes. Choose the first,
Installation on a the local machine
. The installer will then ask for the root password, which is of course secret.At the end of the installation, the installer asks,
Do you want to start \COCO License Manager in order to register this product?
. Answer no because the installer uses a graphical interface, which is usually not possible in a Docker container. - Instead, the non-GUI version of the license manager must be used. Run one of the following commands:
- If you got an activation code, make sure that the Docker container has internet access enabled, then run:
myapp@a6e8af:~$/opt/SquishCoco/bin/cocolic --fetch-license-key
=<activation code>The license key will then be fetched from the license server. Afterwards, the internet access can be disabled again.
- If you have got a license key, run:
myapp@a6e8af:~$/opt/SquishCoco/bin/cocolic --license-key
=<license key> - If you use a license server, run:
myapp@a6e8af:~$/opt/SquishCoco/bin/cocolic --license-server
=<server>:<port>In this case, the Docker container needs to have network access enabled during compilation and whenever a Coco tool runs. When the instrumented program runs, no network access is needed.
If an error message is displayed, contact froglogic support.
Alternatively, you can check if the license is activated or not by running the command below:
myapp@a6e8af:~$/opt/SquishCoco/bin/cocolic --check
- If you got an activation code, make sure that the Docker container has internet access enabled, then run:
- Now Coco is installed in Docker. You can exit the container with the
exit
command. - To enter the container again, run:
$ docker start -ai runner
Coco v7.2.0 ©2024 The Qt Company Ltd.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners.