Bird
Raised Fist0
Denoframework~10 mins

Docker deployment for Deno - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the base image for Deno in the Dockerfile.

Deno
FROM [1]
Drag options to blanks, or click blank then click option'
Adenoland/deno:latest
Bnode:latest
Cpython:3.12
Dubuntu:20.04
Attempts:
3 left
💡 Hint
Common Mistakes
Using a Node.js or Python base image instead of Deno.
Using a generic Ubuntu image without Deno installed.
2fill in blank
medium

Complete the code to copy the application files into the Docker image.

Deno
COPY [1] /app
Drag options to blanks, or click blank then click option'
Anode_modules/
Bsrc/
Cdist/
D.
Attempts:
3 left
💡 Hint
Common Mistakes
Copying only 'src/' when other files are needed.
Copying 'node_modules/' which is not used in Deno.
3fill in blank
hard

Fix the error in the command to run the Deno application with permissions.

Deno
CMD deno run [1] app.ts
Drag options to blanks, or click blank then click option'
A--allow-net --allow-read --unstable
B--allow-net
C--allow-net --allow-read
D--allow-write
Attempts:
3 left
💡 Hint
Common Mistakes
Using only one permission when multiple are needed.
Using '--allow-write' unnecessarily.
4fill in blank
hard

Fill both blanks to expose the correct port and set the working directory.

Deno
WORKDIR [1]
EXPOSE [2]
Drag options to blanks, or click blank then click option'
A/app
B8080
C/usr/src/app
D3000
Attempts:
3 left
💡 Hint
Common Mistakes
Setting working directory to a different path than where files are copied.
Exposing the wrong port number.
5fill in blank
hard

Fill all three blanks to create a multi-stage Dockerfile for building and running a Deno app.

Deno
FROM denoland/deno:latest AS builder
WORKDIR [1]
COPY . .
RUN deno cache [2]

FROM denoland/deno:alpine
WORKDIR [3]
COPY --from=builder /app .
CMD ["deno", "run", "--allow-net", "app.ts"]
Drag options to blanks, or click blank then click option'
A/app
Bapp.ts
C/usr/src/app
D/src
Attempts:
3 left
💡 Hint
Common Mistakes
Using different working directories in builder and final stages.
Caching a wrong or missing file.

Practice

(1/5)
1. What is the main purpose of using Docker for deploying a Deno application?
easy
A. To replace the Deno runtime
B. To write Deno code faster
C. To package the app so it runs the same on any machine
D. To debug Deno code inside the browser

Solution

  1. Step 1: Understand Docker's role

    Docker packages apps with all dependencies so they run consistently anywhere.
  2. Step 2: Relate to Deno deployment

    Using Docker for Deno ensures the app runs the same on any machine without setup issues.
  3. Final Answer:

    To package the app so it runs the same on any machine -> Option C
  4. Quick Check:

    Docker packages apps = To package the app so it runs the same on any machine [OK]
Hint: Docker ensures consistent app environment everywhere [OK]
Common Mistakes:
  • Thinking Docker speeds up coding
  • Confusing Docker with Deno runtime
  • Assuming Docker is for debugging only
2. Which Dockerfile instruction correctly sets the command to run a Deno script named app.ts with all permissions?
easy
A. CMD ["deno", "run", "--allow-all", "app.ts"]
B. RUN deno run --allow-all app.ts
C. ENTRYPOINT deno app.ts
D. CMD deno start app.ts

Solution

  1. Step 1: Identify correct Dockerfile command syntax

    CMD with JSON array syntax is preferred for commands with arguments.
  2. Step 2: Match Deno run command with permissions

    "deno run --allow-all app.ts" runs the script with all permissions; CMD array syntax is correct.
  3. Final Answer:

    CMD ["deno", "run", "--allow-all", "app.ts"] -> Option A
  4. Quick Check:

    Use CMD with JSON array for run command [OK]
Hint: Use CMD with JSON array for Deno run commands [OK]
Common Mistakes:
  • Using RUN instead of CMD for runtime command
  • Omitting --allow-all permission flag
  • Using ENTRYPOINT without arguments array
3. Given this Dockerfile snippet:
FROM denoland/deno:latest
WORKDIR /app
COPY . .
RUN deno cache app.ts
CMD ["deno", "run", "--allow-net", "app.ts"]

What happens when you build and run this container?
medium
A. The app runs with network access allowed
B. The app runs but without network access
C. The container build fails due to missing permissions
D. The app runs but caching is skipped

Solution

  1. Step 1: Analyze Dockerfile commands

    The Dockerfile caches dependencies with "deno cache app.ts" and runs the app with "--allow-net" permission.
  2. Step 2: Understand runtime behavior

    CMD runs the app allowing network access, so the app can use network features.
  3. Final Answer:

    The app runs with network access allowed -> Option A
  4. Quick Check:

    --allow-net enables network access = The app runs with network access allowed [OK]
Hint: Check permission flags in CMD to know app access [OK]
Common Mistakes:
  • Confusing cache step with runtime permissions
  • Assuming build fails without --allow-all
  • Ignoring the effect of --allow-net flag
4. You wrote this Dockerfile:
FROM denoland/deno:latest
WORKDIR /app
COPY . .
CMD ["deno", "run", "app.ts"]

But when running the container, the app crashes with permission errors. What is the fix?
medium
A. Remove COPY command
B. Change WORKDIR to /usr/src/app
C. Use RUN instead of CMD for deno run
D. Add permission flags like --allow-net to the CMD

Solution

  1. Step 1: Identify cause of permission errors

    Deno requires explicit permission flags to access resources like network or file system.
  2. Step 2: Fix Dockerfile CMD to include permissions

    Add flags like --allow-net or --allow-read to CMD so app has needed permissions at runtime.
  3. Final Answer:

    Add permission flags like --allow-net to the CMD -> Option D
  4. Quick Check:

    Permission errors need flags in CMD [OK]
Hint: Add needed --allow-* flags to CMD to fix permission errors [OK]
Common Mistakes:
  • Changing WORKDIR without cause
  • Removing COPY which copies app files
  • Using RUN instead of CMD for runtime command
5. You want to optimize your Deno Docker image by caching dependencies to speed up builds. Which Dockerfile sequence achieves this best?
hard
A. COPY . . RUN deno cache app.ts CMD ["deno", "run", "--allow-all", "app.ts"]
B. COPY deps.ts ./ RUN deno cache deps.ts COPY . . CMD ["deno", "run", "--allow-all", "app.ts"]
C. RUN deno cache app.ts COPY . . CMD ["deno", "run", "app.ts"]
D. COPY app.ts ./ CMD ["deno", "run", "app.ts"]

Solution

  1. Step 1: Understand Docker layer caching

    Docker caches layers; caching dependencies separately avoids re-downloading on code changes.
  2. Step 2: Analyze COPY deps.ts ./ RUN deno cache deps.ts COPY . . CMD ["deno", "run", "--allow-all", "app.ts"]

    Copying only deps.ts and caching it first means dependencies are cached unless deps.ts changes, then copying rest avoids rebuilding cache.
  3. Step 3: Compare other options

    Options A and C copy all files before caching, so cache invalidates on any file change; D lacks caching step.
  4. Final Answer:

    COPY deps.ts ./ RUN deno cache deps.ts COPY . . CMD ["deno", "run", "--allow-all", "app.ts"] -> Option B
  5. Quick Check:

    Cache deps separately for faster rebuilds [OK]
Hint: Cache dependencies before copying app code to speed builds [OK]
Common Mistakes:
  • Copying all files before caching dependencies
  • Skipping deno cache step
  • Not using permission flags in CMD
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard