This is a short tutorial on how use the provided Dockerfile to setup the project environment.You'll essentially do manually what the devcontainer plugin does automatically in IntelliJ.

Note: This setup is more limited than using the devcontainer plugin directly (namely, it won't have as much support for debugging and running tests from the IDE). Furthermore, once you exit the container, except for the folders you mapped to your file system explicitly everything is lost (the command proposed here will map the project repo and the maven cache). This means that as long as everything you do is inside the project folder, it's saved, but it's very important for you to realise that everything outside that folder is lost upon exit of the container. However, this is a less resource-intensive solution that doesn't require any setup and can be a good fit for those that have a less powerful machine and don't want to install everything manually.

This assumes a Linux environment. If you're on Windows, this means you'll need to do this inside a virtual machine (i.e. WSL).

Step 1

You'll need to have Docker installed - you can find an installation tutorial for Ubuntu or other distros.

You might want to run Docker as a non-root user. For that there are two options: - You can setup docker rootless - instructions here - You can add you user to the docker group - sudo usermod -a -G docker $(whoami) (followed by a reboot) (Note that users in the docker group can acquire privileges akin to the root user)

From this point on, it's assumed that one of the options was chosen (if you prefer to run Docker as root, just preprend the Docker commands with sudo.

To check that docker is properly installed, you can run a dummy container:

docker run hello-world

If everything is OK, you should see a hello world message appear. You can now start using Docker. For that, please cd into the root of the repo you cloned earlier.

Step 2

Next you'll need to build the docker image (can take some time to run)

docker build -t humana-ethica .devcontainer

If the build is successful, you should have a docker image called humana-ethica. To check that's the case, run

docker image ls | grep humana-ethica

You should be able to see an entry similar to the following:

humana-ethica                                          latest                     454d38bb6d0d   19 minutes ago   1.39GB

Step 3

If everything is in place, you're almost ready to start the container. First, you'll want to create a directory to cache the maven dependencies (to avoid having to downloading every time a new container is created). For that create an empty directory anywhere in you file system (I'll assume the directory is ../m2, so the FOLDER variable is set to $(pwd)/../m2). Note that the FOLDER variable should be set to an absolute path.

FOLDER="$(pwd)/../m2"

docker run -it --rm \
    -p 8080:8080 \
    -p 8081:8081 \
    -v "$(pwd)":/humana-ethica \
    -v "$FOLDER":/root/.m2 \
    --entrypoint /bin/bash \
    humana-ethica

Now you should be in a new shell with a prompt of the form root@<container_id> (where container_id is just a string of letters and numbers). Furthermore, you should be able to check that there's a process running by running docker ps in a different shell (new window in WSL). To make sure your source code is mapped properly to the container, try to create a file in the container and make sure you see it appear in WSL (e.g. using touch <filename>).

Step 4

To open more shells in that container, you need to first find the container id (by using the docker ps command as before). After that you can just attach to the container.

docker exec -it <container_id> /bin/bash

Note: If you did not setup Docker to be run by your user, you should not create new files from the container (as they will be owned by root and you can't edit/use them outside the container).