My Journey With Docker Commands — Simple Tips



This content originally appeared on DEV Community and was authored by Sudha Velan

Getting Inside a Running Container

When your container is already running, you can access its shell using:

docker exec -it <container_id> bash

If the container doesn’t have Bash installed, try:

docker exec -it <container_id> sh

This lets you debug, inspect logs, check files, or test configurations from inside the container.

When Your Container Isn’t Running (or Exits Immediately)

When a container won’t start, docker exec won’t work.
This is one of the most helpful debugging tricks I learned:

docker run -it --entrypoint=/bin/bash <image_id>

This forces the container to start with a shell, even if its actual entrypoint fails.

Tip:
If /bin/bash is missing, use /bin/sh instead.

Useful Docker Compose Commands

  1. Stop services and remove containers + volumes
docker compose -f <compose_file> down -v

The -v flag removes volumes as well.
Use this when you want a clean setup before starting fresh.

  1. Start services in detached (background) mode
docker compose -f <compose_file> up -d

The -d option keeps everything running in the background so you can continue working.


This content originally appeared on DEV Community and was authored by Sudha Velan