Systems Engineering Laboratory 1
In the first part of the lab we try out the Docker tooling, start our first containers build our own first images and finish with setting environment variables and volumes in the container. The goal is to get well aligned with the core concepts and tools of the Docker technology.
If necessary you can install additional Ubuntu packages in the containers (apt-get update
and apt-get install package
). For example:
net-tools
for using ifconfig
man
for manual pagesmysql-client
for command line MySQL clientWe propose to use multiple terminal windows in order to have some connected to some container and other one can be used to execute commands on the host.
ubuntu:xenial
) and check its system parameters, like memory and CPU. What is the correlation between the container's resource limits and the hosts resource limits?docker ps
and docker inspect
.ip addr show
or ifconfig
) and also on the host using the docker inspect
.nginx
webserver inside the container and check the default web content from the host (apt-get update
and apt-get install nginx
).curl
CLI tool on the host.docker ps -a
)service nginx start
)In the following the Docker images will be created:
retelab/manual-java
: created manually, contains JDK and starts a bash shell.retelab/java
: created automatically using Dockerfile, contains JDK and starts a bash shell.retelab/hello-world
: created automatically using Dockerfile based on the retelab/java
and starts the Hello world
application.retelab/java-gradle-project
: it is based on the retelab/java
, mounts any Gradle-based Java project as a volume and executes it.Based on the ubuntu:xenial
image prepare a new base image for your Java-based projects:
Start a new ubuntu:xenial
container.
Install JDK (openjdk-8-jdk
Ubuntu package).
Create a Hello world
Java application inside the container. Use only the javac
compiler and a simple text editor such as mcedit
, vim
, nano
or emacs
. Hints:
# compile the project
javac HelloMain.java
$ # run the generated file
java HelloMain $
Execute the Hello world
application.
Save the running container as a new Docker image, named retelab/manual-java
(docker commit
).
Start a new container based on the new retelab/manual-java
image and test your Hello world
application again.
Hint: create a new subfolder for each image definition and put the Dockerfile
and other related content into that folder.
Dockerfile
syntax create the same image definition as before: based on the Ubuntu base image, install Java, add and compile the Hello world
application (Hint: using the ADD
Dockerfile command, you can add files into a container). Build this as a new image retelab/java
(docker build
).retelab/java
image and test your Hello world
application again.retelab/java
and provide a COMMAND
command-line argument to docker run
and run the container using the Hello world
application instead of the bash
shell.retelab/hello-world
based on the retelab/java
image (defined by a new Dockerfile
) that starts the Hello world
application instead of the bash
shell (a CMD
command in the Dockerfile
). (Hint: take care on the WORKDIR
in order to execute the commands in the right directory)Hello world
application to also print the value of the RETE_ENV
Linux environment variable. Rebuild your two images after the changes.retelab/java
, set the RETE_ENV
environment variable (export RETE_ENV=production
) and test your Hello world
application again.retelab/hello-world
by adding the RETE_ENV
variable to the docker run
command (as command line parameter and not using the export command) and check the output.docker ps
, grep
, cut
, xargs
, docker rm -f
. Check the manuals if necessary (man command
))Clone the repository from https://github.com/FTSRG-ReteLab/docker-lab and run the project with the following Gradle command:
./gradlew run $
It will fail as the MySQL server is not available.
Start a new container running the MySQL server with username root
and password retelab
:
docker build -t mysql-backend mysql-backend
$ docker run -d mysql-backend $
This contains the golf
dataset. The container does not have interactive shell, it starts in the background (-d parameter). Check if the container is running (docker ps
) and check its IP address.
Start and attach to a new process (bash shell) inside the running MySQL container using docker exec -ti
and check the running processes using ps ax
. Test the command line MySQL client (mysql -u root -pretelab -h localhost
). (Hint: do not use docker attach
to connect to the container, since it attaches the terminal to the main process of the container, which is a MySQL server process running in the background. Let's start a new bash process using docker exec
).
Test the MySQL connection from outside the MySQL container (e.g. from the host or from an other ubuntu:xenial
-based empty Ubuntu container). Install the MySQL client on the host machine or in a new Ubuntu container:
sudo apt-get install mysql-client $
To join to the MySQL server, use the following command:
mysql -u root -pretelab -h IP_ADDRESS $
Define a new Docker image retelab/java-gradle-project
using Dockerfile
based on the previous retelab/java
image. Add a new directory to the filesystem (mkdir /project
), set it as workdir (WORKDIR
command in the Dockerfile
) and set the default command (CMD
) to ./gradlew run
. Build the image.
Start a new container based on the retelab/java-gradle-project
, add the git project's root dir to the container's /project
directory as a volume (-v
parameter). Take care on the connection string: modify the MySQL server address to the IP of your MySQL container.
Clean up all the running containers.
Using the docker-compose
technology define the infrastructure in the form of a docker-compose.yml
file.
mysql-client
project as a volume to the Java Gradle project service (volumes
property in the docker-compose.yml
).links
property in the docker-compose.yml
). Take care on the connection string: modify the MySQL server address to the name of the link to your MySQL service in the docker-compose.yml
file. This name can be used as hostname.Fire up the infrastructure with a single command (docker-compose up
).