Running Docker
Grade a Dockerized web app
In this guide we explore how to grade a containerized web application with CodeGrade. Students submit a small web app together with a Dockerfile; CodeGrade builds the image, runs the container, and checks that the website actually responds over HTTP.
The same Setup + Tests pattern works for any Dockerized project — Node, Go, .NET, a database — not just the Flask example used here.
Consider the example submission below. It is a tiny Flask web server that listens on host 0.0.0.0, port 8080, and serves three endpoints:
GET /
Hello, CodeGrade!
GET /health
OK
GET /add/<a>/<b>
the sum of a and b
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Hello, CodeGrade!\n"
@app.route("/health")
def health():
return "OK\n"
@app.route("/add/<int:a>/<int:b>")
def add(a, b):
return f"{a + b}\n"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)Note: This guide drives Docker entirely from Bash Script blocks rather than a built-in language block, so it works regardless of the language inside the container.
AutoTest Setup
In the Setup phase we install Docker, start the daemon, and open the Docker socket so the (non-root) Tests phase can use Docker without sudo. The Setup phase has internet access and sudo rights, so this is the right place to do all privileged work.
Add a Script block to the Setup phase with the following script:
Note — why
chmod 666the socket? The grading user isn't in thedockergroup, and group membership only takes effect on the next login — so it can't help within a single run. Opening the socket during Setup (wheresudoworks) lets the Tests phase run plaindockercommands. This is safe for a throwaway grading sandbox.
AutoTest Tests
In the Tests phase we upload a small Test.sh script, build the student's image, run it, and check that the website responds. Configure the blocks as follows (the names in quotes match the screenshot below):
Add an Allow internet block as the outermost block. The build needs to pull the base image and install packages, and the Tests phase has no internet by default.
Inside it, add an Upload Files block ("Upload test") and upload the
Test.shscript shown below.Also inside Allow internet, add a Connect rubric block ("Running the App") and select your rubric category. This ties the pass/fail outcome to the grade.
Inside Connect rubric, add an IO Test block ("Running docker"). In its command field, copy the uploaded script into the working directory and run it:
Inside the IO Test, add a Substring Match block ("Checking the App"). Leave Input empty and set Expected in output to
Hello, Web app is up!. Keep it case-sensitive and include whitespaces.

Test.sh with a Substring Match, nested inside Connect rubric and Allow internet.The Test.sh script does the actual work: it builds the image, runs the container, and prints Hello, Web app is up! when the site responds. The Substring Match looks for exactly that line, so a working submission passes and fills the rubric category.
Note: The Upload Files command copies the fixtures into the working directory (
cp $FIXTURES/*.* .) soTest.shsits alongside the student'sDockerfileandapp.py. Depending on your CodeGrade version this variable may be$UPLOADED_FILES— ifTest.shis "not found", check that first.
Tip: To grade a specific endpoint instead of just "is it up", change what
Test.shprints the marker for, e.g. onlyecho "Hello, Web app is up!"whencurl .../add/3/5returns8.
Warning: The container listens on port
8080. If your students' apps use a different port, update both theDockerfile(EXPOSE) andTest.sh. Reaching the container by its IP avoids host port-mapping conflicts when several submissions are graded in parallel.
Test and publish your AutoTests
Always test your configuration before releasing it to students.
Press Build snapshot at the bottom of the test block sidebar.
When prompted, upload the three reference files above as your Test submission.
Confirm the snapshot run fills the rubric category to 100% and that the output shows
PASS: website is up.Once you're happy, click Publish snapshot to make the tests available to students.
Note: Docker images and
pip installcan make the first build slow. If a snapshot times out, wrap the test Script in a Timeout each block and raise the limit (the default is 120 seconds).
Conclusion
You've built an assignment that grades a real, containerized web application end to end: CodeGrade installs Docker in Setup, builds the student's image, runs it, and verifies the site responds — all tied to a rubric. The same Setup + Script + Allow internet pattern extends to any Dockerized project.
For more on the blocks used here, see the AutoTest V2 Blocks guide, or reach out to our support team at support@codegrade.com.
Last updated