This document outlines how you can setup a containerized testing/development environment quickly using docker. Using a containerized dashboard image allows for a faster and reproducible test setup. We first have to build the Docker image and then run the container.
$ docker build -t wiki-edu-dashboard .
$ docker run --net=host -it -v /path/to/WikiEduDashboard:/usr/src/app wiki-edu-dashboard
Make sure the docker daemon is running. Else, service docker status
. Then, from the root of your development directory (WikiEduDashboard
), issue the build command:
$ docker build -t wiki-edu-dashboard .
This builds the wiki-edu-dashboard
container image using the Dockerfile. The dashboard container image is based on the official ruby:2.5.0
base image. The container image contains all the necessary dependencies as well as an initialized MariaDB database as required by the Wiki Edu Dashboard.
The current docker image can be used for testing, local deploys or development purposes. docker run
initializes the setup and spawns a container which starts serving the dashboard on http://localhost:3000
. Also, this requires port 3000
to be open on the host.
For a developer's ease of use, it is desirable to have the container auto update as the source code changes in the development directory. Therefore, we use Docker volumes to mount the local directory and have its real-time changes accessible inside the container. Run the container with the -v
option as follows:
$ docker run --net=host -it -v /path/to/WikiEduDashboard:/usr/src/app wiki-edu-dashboard
This starts the container with host networking and allows /path/to/WikiEduDashboard
(developer's working directory) to be accessible from the WORKDIR
of container. For WikiEduDashboard Docker image, the working directory has been set as /usr/src/app
. Once the container starts, you should start expecting the following prompts and yarn start
to have started with its status messages waiting for live changes.
[ ok ] Starting MariaDB database server: mysqld ..
+ redis-server --daemonize yes
+ rails s -d -b 0.0.0.0
=> Booting WEBrick
=> Rails 5.1.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
..
At this point, developers can continue working in their local work directories and the changes would be reflected inside the container. Live changes are visible on http://localhost:3000
from the host.
The above container can also be spawned without the need of volumes, thus freezing the code in the container to be the same as latest image built using docker build
. Developers can also tag multiple container image builds using docker build -t name:tag .
To deploy a test build:
$ docker run --net=host -it wiki-edu-dashboard
Open a browser on the host at http://localhost:3000
and start testing.
Some useful commands and tools that can be used to monitor and administer the containers are:
ctop
docker images
docker inspect <container id>
Further Reference: https://docs.docker.com/reference/
If you are using Windows OS for development and haven't configured Git for line ending settings, you may encounter error during docker image building process. This is caused by different line ending default behaviors between Windows and Linux systems. The error will read something like below:
./db_init.sh /bin/sh^M: bad interpreter: No such file or directory
To keep the line ending settings consistent between the systems, one option is to configure Git to use no line ending conversion so that it uses the line ending setting that comes from the repository.
git config --global core.autocrlf input