Skip to content

Docker with Scholar

Brandon Spears edited this page Aug 23, 2019 · 3 revisions

Install Docker

Docker is a tool that allows you to run a software package in a lightweight container on your machine. This allows you to not have as much overhead as a virtual machine, while still having most of the benefits. To install Docker CE for your machine, you will either need to create a Docker Hub account, or download it from https://docs.docker.com/v17.12/docker-for-mac/install/. We recommend creating a Docker Hub account if you are a developer, otherwise you don't really need it.

Using docker requires a feature called Hyper-V (Windows), or HyperKit (Mac). This will not allow you to use Oracle Virtual Box at the same time (enable one or the other). If you need to use Virtual Box, please use Docker Toolbox instead.

Build an image

After you install Docker, make sure you start it. You can check if it is installed properly by running docker -v in a terminal. Navigate to where you have the files for Scholar located, and make sure that that there is a file called Dockerfile in that directory. If you are a developer run docker build -t ucrate -f Dockerfile.dev ., otherwise run docker build -t scholar .

This should start a process of downloading and building the image for Scholar. This process should take about 10 minutes if you haven't run it before.

Start a container

After the image is built, it should exit with Successfully tagged. If it doesn't, please troubleshoot accordingly. The next step is to start a container form the image that you just built. If you are not a developer, simply run docker run -it --rm -p 3000:3000 scholar and follow the instructions in the terminal. If you are a developer, then run docker run -ti --rm -p 3000:3000 -v $(pwd):/home/dev/ucrate ucrate bash.

It is recommended that you create a bash variable with the location of ucrate and use that instead of $(pwd). You can use it to go to that location from the prompt and it is easier to change at a later date. This may not work for non-Linux systems, where you will have to specify the full path to the ucrate directory

You should now see something that looks like dev@c401310eb1b2:~/ucrate$. Check to make sure that the ucrate directory was mounted correctly by running ls -la. If it shows the entire application, then you are good to go. If you want to deploy quickly, simply run source script/docker.sh migrate inside the container to run a script geared for docker setups to start everything and run all the necessary migrations for a new setup. Migrations take a few minutes to run, so don't panic if they take a while. If you are not using a new setup (has run outside of docker), then run source script/dev.sh s instead. This will start a tmux session called localhost with everything running including sidekiq. It is recommended to stop redis and sidekiq before exiting.

If you get an error from Redis, you can run rm dump.rdb to potentially fix it. If rails complains about it being running already and you are sure that it isn't running, simply clear the file tmp/pids/server.pid and restart the server.

Exit the container

To exit the docker container, simply press Ctrl + D from the terminal to exit, or tmux kill-server, then Ctrl + D if you are a developer. Due to the way that the container was started, this will remove the container and clean up for you. You don't need to rebuild the image every time you start a container, however you can if you want to. If you don't want an old version of scholar, add the --no-cache option after the word build.

Non-Developer TLDR

  1. Install Docker
  2. Go to the scholar directory
  3. docker build -t scholar .
  4. docker run -it --rm -p 3000:3000 scholar
  5. source script/docker.sh migrate
  6. To exit, press Ctrl + D

Developer TLDR

  1. Install Docker
  2. Go to the ucrate directory
  3. docker build -t ucrate -f Dockerfile.dev .
  4. docker run -ti --rm -p 3000:3000 -v $(pwd):/home/dev/ucrate ucrate bash
  5. source script/dev.sh s
  6. To exit, tmux kill-server then Ctrl + D