Skip to content

Docker

When working on a project most of the time you are making use of a lot of different tools. For example, you might be using a database, a message broker, a cache, etc. All these tools need to be installed and configured on your machine. This can be a tedious task and can take a lot of time. Docker is a tool that can help you with this. Docker allows you to run applications in containers. A container is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings.

In the Individual Project of Studio Smart Cities you are building a website which exists of a front-end, API, database, tunnel, ... a lot. To help you with this you will be using Docker. On this page you can find information about how to set-up the docker environment for your project, in your Gitlab project.

Contents

There are already files/folder in your Gitlab project for docker, some to point out:

  • docker-compose.yml: This file contains the configuration for your docker environment. It contains the services that will be running in your docker environment. For example; nginx, php, mysql, ...
  • docker/: This folder contains the configuration for the different services. For example; nginx, php, mysql, ...
  • .env: This file contains the environment variables that will be used in your docker environment. For example; Webserver ports, MySQL password, ...

Running docker on your computer

To run docker on your computer you need to install Docker Desktop. You can find the installation instructions on the Docker website. (Note: When you start Docker Desktop for the first time, you will be asked to create an account. DON'T DO THIS!)

Usage

To start your docker environment you can run the following command in your terminal, from your project root:

1
docker-compose up -d

or to rebuild the docker environment:

1
docker-compose up --force-recreate --build

This will create the docker containers and run them automatically. You can check if the containers are running by opening your webbrowser and visiting http://localhost.

Troubleshooting

The most common problem when you try to run the docker environment is that the ports are already in use. To fix this it is recommended to stop all other services that are running on the ports 80 and 3306.

If you have already a MySQL server running on port 3306, you can stop it by following these steps (Windows):

  • Visit the Services panel in the Task Manager.
  • Find the service called 'MySQL' and right-click and select 'Properties'.
  • Select 'Stop'.
  • Set 'Startup type' to 'Disabled'.
  • Click on 'Apply' and then 'OK'.
  • Now you can try to run the docker environment again.

Services

By default you can find the following services in your docker environment:

  • Nginx (port 80)
  • PHP
  • MariaDB (MySQL) (port 3306)
  • PhpMyAdmin

Make sure you are not running any other services on these ports.

MariaDB (MySQL)

The details of your MySQL database are:

Key Value
hostname mariadb
user root
password [You can find the password in the .env-file. ]