DEV Community

Sudha Velan
Sudha Velan

Posted on

My Journey With Docker Commands — Simple Tips

Getting Inside a Running Container

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

docker exec -it <container_id> bash
Enter fullscreen mode Exit fullscreen mode

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

docker exec -it <container_id> sh
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)