×
Back to book

Developing Your Application Using Docker

Using Docker to run and develop your SpringBot or C#Bot application.

Requirements

  • Have an application built by Codebots that is ready to run.

Install Dependencies

The first thing you need to do is make sure you have the correct software installed for your operating system. The requirements are:

  • Git
  • Docker
  • Docker Compose
  • Editor

Git

Follow the official instructions found here.

Use the default options for the installation.

This is a command line tool so there will be no interface.

Docker

Follow the official instructions found,

Mac

Linux

Windows

For Windows, there are two versions that can be used, the above linked version requires the following,

  • Pro, Enterprise, or Education (Build 15063 or later).
  • Hyper-V and Containers Windows features must be enabled

If your computer does not meet these requirements, please have a look at using the Pre-Built Virtual Machine instead. See here for instructions.

Docker Compose

Not required if you are using Mac OS 10.10 or Newer, compose will already be installed with Docker.

Follow the official instructions found here.

Linux (Ubuntu)

Once installed, make sure you add your user to the docker user group.

  1. sudo usermod -a -G docker $USER - Add yourself to the docker user group.
  2. newgrp docker - Reload the new settings

Editor

This is only needed to make changes to your application.

For the purpose of these instructions we will use Visual Studio Code. Please feel free to use your own preferred editor of choice.

Install VS Code by following the official documentation here.

More details on how this can be setup can be found in the following links,

Additionally, a useful extension for working with Docker can be found here. This is not required but can simplify some of the following actions.

Run your application

  1. Make sure Docker is running. For Mac or Windows, this can be done by ensuring your Docker Desktop application has been started.

  2. Ensure your drive is shared with Docker.
    Right click on the taskbar icon (seen above), select "Settings", then "Shared Drives", then select your drive, and click "Apply". It may ask for your password.

  1. Open a terminal (Powershell if you are on Windows)

  2. Create the repository directory if it does not already exist.

    # Linux/Mac 
    mkdir ~/repository
    
    # Windows 
    New-Item -ItemType directory -Path C:\repository

    If this worked you will see no errors.

  3. Change directory to this new folder the location that you wish to store your source files.

     # Linux/Mac 
     cd ~/repository
    
     # Windows 
     cd C:\repository
  4. Clone your projects source code using the details found on your project home page.

    git clone [URL]

    Replace the [URL] in the above command with the URL shown on your apps dashboard (see screenshot below).

  5. Change directory into your project folder

    cd [projectName]

    Replace [projectName] in the command above with the folder name of your project.

  6. If you don't have a docker-compose.yml in your [projectName], download this file and place inside of your [projectName]:

  7. Kick start your docker setup:

     # Please ensure that there is a file called docker-compose.yml 
     # in this directory before running this command.
     # To confirm, run `ls docker-compose.yml` and see if the file name is listed.
     docker-compose up -d

    Now wait for it to finish. This can take a couple of minutes.
    While waiting, you can watch the logs. See "Useful Commands" below.

    If you are using C#Bot, for first time starting your application you will need to create your initial database migration then restart your server.

    docker-compose exec server dotnet ef migrations add init
    docker-compose restart server
  8. You can now access your application on:
    SpringBot
    http://localhost:8000

    C#Bot
    http://localhost:8001

Useful Commands

Docker Compose command-line reference can be found at https://docs.docker.com/compose/reference/ and Docker child command can be found at https://docs.docker.com/engine/reference/commandline/docker/.

TLDR; Use docker-compose exec [client|server] [command] to run any command inside a running container.

General

See activity / watch logs

Client

docker-compose logs -f client

Server

docker-compose logs -f server

Restart

Client

docker-compose restart client

Server

docker-compose restart server

Open Shell

Client

docker-compose exec client sh

Server

docker-compose exec server sh

CsharpBot

Create Migrations

docker-compose exec server dotnet ef migrations add init

Drop Database

docker-compose exec server dotnet ef database drop

SpringBot

Run Server

docker-compose exec server sh -c "./gradlew bootRun"

Stop Server

docker-compose exec server sh -c "pkill java"