You now have a Dockerfile—the recipe. These commands let you make the package, start it, and see what it is doing.

Build an image

Use docker build to create an image from a Dockerfile.

docker build -t my-api:1.0 .

Meaning:

The build context is important because Docker can only copy files from inside that context.

Run a container

Use docker run to start a container from an image.

docker run -d --name my-api -p 3000:3000 my-api:1.0

Meaning:

Port mapping format is host port first, container port second.

Check running containers

docker ps
docker ps -a

docker ps shows running containers. docker ps -a also shows stopped containers.

Read logs

docker logs my-api
docker logs -f my-api

-f follows logs in real time.

Debug inside a container

docker exec -it my-api sh

This opens a shell inside a running container. Some images use bash; minimal images may only have sh.

Stop and remove

docker stop my-api
docker rm my-api
docker rmi my-api:1.0

Stopping a container does not delete it. Removing a container does not remove the image.

Quick revision