Working with Your Containers

Due Fri, 12/04 at 11:59pm

When working with Docker containers, it can be confusing to know whether you should run a command on your host computer (your laptop) or inside a Docker container. This guide will help clarify when to use each.

Your Host Computer

Run commands on your host computer when:

  • You’re editing files (code, configuration, etc.)
  • You’re creating or deleting files
  • You’re using Git (commits, pushes, branches)
  • You’re viewing files in your file explorer or editor

I recommend navigating to project02-fall2026 on your terminal and typing code . to edit your code files on your laptop (host machine).

Your Containers

Run commands inside containers when:

  • You need to install packages (npm, poetry, pip)
  • You’re running tools that require the container’s environment (linters, formatters, database clients)
  • You’re executing code that needs container-specific dependencies
  • You’re querying the database directly

Why this matters:

  • Your host computer may not have Node.js, Python, or PostgreSQL installed
  • Containers have isolated environments with all the dependencies pre-installed
  • File changes on your host are automatically reflected in containers (via volume mounts)
  • But package installations and tool execution must happen inside the container where those tools exist

1. Always install new packages on the correct container:

Frontend (Node.js packages):

# Install a new npm package (e.g., antd)
docker exec -it todo_frontend npm install antd

# Or if you've updated package.json, reinstall all dependencies
docker exec -it todo_frontend npm install

Backend (Python packages):

# Add a new package to pyproject.toml first, then install
docker exec -it todo_backend poetry add package-name

# Or if you've updated pyproject.toml, reinstall all dependencies
docker exec -it todo_backend poetry install

2. Always run the linters on the correct container:

You’ll set up the linters and formatters in the next step. Once you have, you’ll run them inside the todo_frontend and todo_backend containers using docker exec (just like the package installs above).

3. Query your database

Connect to PostgreSQL:

# Connect to the database container
docker exec -it todo_db psql -U postgres -d todo_db

# Once connected, you can run SQL queries:
# SELECT * FROM todos;
# \dt  (list all tables)
# \q   (quit)

Run a single SQL query without entering interactive mode:

docker exec -it todo_db psql -U postgres -d todo_db -c "SELECT * FROM todos;"

← Back to Project 2 Instructions

UNC Asheville Department of Computer Science