Skip to content

Docker Workflow for Development

Max Patiiuk edited this page Jul 19, 2021 · 12 revisions

Instructions for setting up the development environment

This tutorial assumes basic knowledge of Docker and Docker Compose.

You can read these tutorials on Docker and Docker Compose to get started.

Installation

  1. Install Docker and Docker compose:

    On macOS (assuming brew is installed):

    brew install --cask docker

    On Linux:

    sudo apt-get install \
      apt-transport-https \
      ca-certificates \
      curl \
      gnupg \
      lsb-release
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    echo \
      "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli containerd.io
    sudo groupadd docker
    sudo usermod -aG docker $USER
    newgrp docker
    sudo systemctl enable docker.service
    sudo systemctl enable containerd.service
    curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh
    docker plugin install --grant-all-permissions vieux/sshfs
  2. Checkout the repository (assuming git is installed)

    git clone https://github.com/specify/specify7/
    cd specify7
  3. Build the images and run the containers:

    docker compose up
    # or, if you are on a legacy version:
    docker-compose up
  4. Make the code changes you want. Both the backend and the frontend would be updated in real-time.

    If you want to receive audible notifications when the rebuild process is finished, here are the instructions for setting that up

Afterward, you can stop the containers by pressing Ctrl+C or typing docker compose down in a separate terminal window.

Running the server on a remote machine

A common use case for using Docker is having the containers run on a dedicated machine. This frees up resources on your laptop for other tasks.

This can be atchived in Docker by using code syncing and Docker contexts.

Configuring Docker Contexts

Docker Contexts allows to manage remote Docker servers.

Read more about them here

And here is how to use them

For example:

# Create a context
docker context create maxxxxxdlp-pc --default-stack-orchestrator=swarm --docker "host=tcp://192.168.50.165:2375" --description "Home Ubuntu PC"

Then, you can define default context like docker context use maxxxxxdlp-pc or define an alias and prepend it to your commands:

alias dd="DOCKER_CONTEXT=maxxxxxdlp-pc "
dd docker container ls

Configuring Code Sync

We need to update the remove server in real time as soon as any code changes are made. mirror is designed just for that task.

Instructions for setting up Code Sync with Docker

The commands I used:

# Add this to your .zshrc file:
alias sync_client='docker run --rm --init -it -u $(id -u):$(id -g) -v $(pwd):/data \
  quay.io/stephenh/mirror client \
  --local-root /data \
  --remote-root /data \
  --host 192.168.50.165 \
  --include "./seed-database" --exclude "./idea" --exclude "nohup.out"'
alias sync_server='docker run \
  --rm --init -it -u $(id -u):$(id -g) -v $(pwd):/data -p 49172:49172 \
  quay.io/stephenh/mirror server'

Then just run sync_server on the server and sync_client on the client machine.