First steps - Getting to know docker [OUTDATED]

This tutorial is designed to explain docker and what you can do with it.

Table of Contents

Getting to know docker

Prerequisites

For this tutorial you just need terminal access and being able to run the system!

Introduction

So what is this 'docker' thing you keep reading? Honestly I probably cannot explain it better than their site does.

In very short: It allows running multiple virtual machines, computers, on your own (single) computer, all with a single command (okay, and a configured file). As it says on their site it eliminates the differences between machines and makes overall installation of a system like this ez pz.

Steps to take

Looking around

  1. Open the Docker-compose.yml file
    1. Notice several containers, each starting with ther name
    2. Each container starts with an image, the base machine
    3. It has some configuration, for example mapping ports
    4. It has some volumes
    5. This is the file that defines which containers to use and how to build them
      1. It is what instructs the `docker-compose up` command what to do
  2. Open a Dockerfile
    1. These files add additional instructions on how to build each container
      1. It defines actions to do on the images (which are downloaded from dockerhub)
      2. Building means preparing, a container is first build and can later on be run
        1. You can store containers when they are build, you can even upload and download them!
    2. It starts with a `FROM` command, defining the base image
    3. It can execute shell commands using the `RUN` keyword
    4. it can add files to the container using the `ADD` keyword
    5. it can define a command to run when the container starts (which is later) using the `CMD` keyword
    6. Now about this specific Dockerfile:
      1. It is for the core microservice, notice how it is in the core repostiory (this is to reduce dependency issues)
        1. Understanding each command requires some experience with Linux and is out of the scope for this tutorial
      2. It starts with a base image and sets some settings
      3. Next it installs some software dependencies we have
        1. Starting with adding the PHP 7 ppa repository
        2. After which it installs several PHP-7.1 extensions and general utility packages
        3. It installs composer, a PHP dependency manager
      4. After the dependencies it adds the bootstrap.sh file for the core
        1. The bootstrap file (script) is basically a set of shell commands to run after each other
      5. Finally it defines the command to run when starting the container
        1. In this case, this is mostly delegated to the bootstrap.sh file
    7. You can find more information about the Dockerfile here.

Common docker commands

This section is a more detailed version of the docker section on the usage tips page.

Tip!

If you are running into errors, try prepending the command with `sudo`

  1. If you haven't already, fire up the system using `docker-compose up d` in `../oms-docker/docker`
  2. Now, from the same directory, use docker-compose down -v
    1. This should shut the system down and remove the container volumes, resetting the data inside the containers
  3. Fire up the system again, this time with `docker-compose up` (without the -d)
    1. This keeps the terminal attached (not detached) to the docker process
      1. Which allows you to see the logs as it is running!
  4. Right click on the terminal and select to open a new terminal
    1. You should now have 2 terminals, both in `oms-docker/docker/`, 1 still running the system, one ready for use.
  5. In the new terminal issue the command `docker-compose logs omscore`
    1. This shows just the logs from the core microservice!
  6. Try running `docker-compose logs` instead
    1. This shows all the logs!
    2. You can even try `docker-compose logs -f` to stay attached to the logs
  7. Execute `docker-compose exec omscore bash`
    1. You are now in a terminal inside the omscore container!
      1. Which is running Ubuntu
    2. You can look at the files and processes running in the container, for example type `ps` in the container to see the processes
    3. Execute the command `php artisan migrate:refresh --seed`
      1. You have just reset the omscore database!
      2. For more core related commands see the usage tips page.
    4. Exit the container by typing exit
      1. You should now be back in your own terminal
  8. Execute `bash ./oms_setup.sh --reset` in `oms-docker/docker`
    1. This resets all the containers you have!
  9. Build a single container using `bash ./oms_setup.sh -c=traefik`
    1. Using the -c parameter you can specify a single container to perform actions on
  10. Try running the system again, you'll notice it will act similar to the first installation of it.

You should now know the basic docker commands, enough to perform basic tasks with the system!