---
title: "Leveraging Docker with TensorFlow Models & TensorFlow.js for a Snake AI Game"
description: "A browser-based Snake game whose AI mode uses a TensorFlow.js feedforward network (dense layers 5→256→512→256→3, Adam at 0.001, MSE loss) to choose left, forward or right from the snake's surroundings, retraining on its recorded moves after each game."
url: "https://swe.quest/articles/leveraging-docker-with-tensorflow-models-tensorflow-js-for-a-snake-ai-game-0310fd6dfebd2c17"
canonical: "https://www.docker.com/blog/leveraging-docker-with-tensorflow/"
source: "Docker"
published: "2025-03-18"
difficulty: "medium"
kind: "How-to"
reading_minutes: 10
tags: ["containers","machine-learning","javascript","gaming"]
---

# Leveraging Docker with TensorFlow Models & TensorFlow.js for a Snake AI Game

A post on [Docker](https://swe.quest/sources/docker.md), published 2025-03-18, 10 min read, How-to. Original: [https://www.docker.com/blog/leveraging-docker-with-tensorflow/](https://www.docker.com/blog/leveraging-docker-with-tensorflow/)

## Summary

A browser-based Snake game whose AI mode uses a TensorFlow.js feedforward network (dense layers 5→256→512→256→3, Adam at 0.001, MSE loss) to choose left, forward or right from the snake's surroundings, retraining on its recorded moves after each game. The static site is served from an nginx:latest container built with a two-line Dockerfile, and a bind-mounted volume gives live reload during development without rebuilding the image. The walkthrough covers the game loop, mode switching, training and prediction code, and a fix for Docker Desktop file-sharing mount errors.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Games](https://swe.quest/tags/gaming.md) (Domains)

## Prerequisites

- Basic JavaScript ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- Docker basics ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))

## Keywords

Docker, TensorFlow.js, Docker Desktop, Nginx, Docker Compose

## Related posts

- [Build a dinosaur runner game with Deno, pt. 2](https://swe.quest/articles/build-a-dinosaur-runner-game-with-deno-pt-2-c8e56eec683a558c.md): Deno · 2025-12-15 · Medium · 10 min read · Games, JavaScript, Frontend, Browsers
  Stage 2 of a Deno dinosaur runner tutorial turns a static landing page into a playable HTML5 canvas game.
- [Making ML-powered web games with Transformers.js](https://swe.quest/articles/making-ml-powered-web-games-with-transformers-js-c633a2c1d80dea56.md): Hugging Face · 2023-07-05 · Medium · 8 min read · Inference & serving, Computer vision, JavaScript, Games, Frontend
  Doodle Dash is a Quick, Draw!-style sketch-guessing game that runs entirely in the browser, using a MobileViT-small model (5.6M parameters, ~20 MB) fine-tuned on Google's Quick, Draw! dataset.
- [Build a dinosaur runner game with Deno, pt. 3](https://swe.quest/articles/build-a-dinosaur-runner-game-with-deno-pt-3-210f2045426eb0c9.md): Deno · 2025-12-22 · Medium · 9 min read · Games, JavaScript, Frontend
  Part 3 of a Deno tutorial series adds obstacles and collision detection to a canvas-based dinosaur runner game.
- [How to Build, Run, and Package AI Models Locally with Docker Model Runner](https://swe.quest/articles/how-to-build-run-and-package-ai-models-locally-with-docker-model-runner-acbc6d65548e5373.md): Docker · 2025-06-12 · Medium · 6 min read · Inference & serving, LLMs, Containers, Developer tools
  Docker Model Runner, enabled as a beta feature in Docker Desktop 4.40+, pulls GGUF-format LLMs from Docker Hub or Hugging Face and runs them locally via the \`docker model\` CLI or an OpenAI-compatible HTTP endpoint on localhost.
- [Docker Model Runner on the new NVIDIA DGX Spark: a new paradigm for developing AI locally](https://swe.quest/articles/docker-model-runner-on-the-new-nvidia-dgx-spark-a-new-paradigm-for-developing-f03f09cdcb90d612.md): Docker · 2025-10-14 · Medium · 7 min read · Inference & serving, Containers, LLMs, AI for coding, Hardware
  Docker Model Runner now supports NVIDIA DGX Spark, a compact Grace Blackwell GB10 workstation with 128GB of unified memory, for running large models locally.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
