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
- Open the Docker-compose.yml file
- Notice several containers, each starting with ther name
- Each container starts with an image, the base machine
- It has some configuration, for example mapping ports
- It has some volumes
- This is the file that defines which containers to use and how to build them
- It is what instructs the `docker-compose up` command what to do
- Open a Dockerfile.dev
- These files add additional instructions on how to build each container
- It defines actions to do on the images (which are downloaded from dockerhub)
- Building means preparing, a container is first build and can later on be run
- You can store containers when they are build, you can even upload and download them!
- It starts with a `FROM` command, defining the base image
- It can execute shell commands using the `RUN` keyword
- it can add files to the container using the `ADD` keyword
- it can define a command to run when the container starts (which is later) using the `CMD` keyword
- Now about this specific Dockerfile:
- It is for the core microservice, notice how it is in the core repostiory (this is to reduce dependency issues)
- Understanding what each command requires some experience with Linux and is out of the scope for this tutorial
- It starts with a base image and sets some settings
- Next it installs some software dependencies we have
- Starting with adding the PHP 7 ppa repository
- After which it installs several PHP-7.1 extensions and general utility packages
- It installs composer, a PHP dependency manager
- After the dependencies it adds the bootstrap.sh file for the core
- The bootstrap file (script) is basically a set of shell commands to run after each other
- Finally it defines the command to run when starting the container
- In this case, this is mostly delegated to the bootstrap.sh file
- It is for the core microservice, notice how it is in the core repostiory (this is to reduce dependency issues)
- You can find more information about the Dockerfile here.
- These files add additional instructions on how to build each container
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` |
- If you haven't already, fire up the system using `docker-compose up d` in `../oms-docker/docker`
- Now, from the same directory, use docker-compose down -v
- This should shut the system down and remove the container volumes, resetting the data inside the containers
- Fire up the system again, this time with `docker-compose up` (without the -d)
- This keeps the terminal attached (not detached) to the docker process
- Which allows you to see the logs as it is running!
- This keeps the terminal attached (not detached) to the docker process
- Right click on the terminal and select to open a new terminal
- You should now have 2 terminals, both in `oms-docker/docker/`, 1 still running the system, one ready for use.
- In the new terminal issue the command `docker-compose logs omscore`
- This shows just the logs from the core microservice!
- Try running `docker-compose logs` instead
- This shows all the logs!
- You can even try `docker-compose logs -f` to stay attached to the logs
- Execute `docker-compose exec omscore bash`
- You are now in a terminal inside the omscore container!
- Which is running Ubuntu
- You can look at the files and processes running in the container, for example type `ps` in the container to see the processes
- Execute the command `php artisan migrate:refresh --seed`
- You have just reset the omscore database!
- For more core related commands see the usage tips page.
- Exit the container by typing exit
- You should now be back in your own terminal
- You are now in a terminal inside the omscore container!
- Execute `bash ./oms_setup.sh --reset` in `oms-docker/docker`
- This resets all the containers you have!
- Build a single container using `bash ./oms_setup.sh -c=traefik`
- Using the -c parameter you can specify a single container to perform actions on
- 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!