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:
-t my-api:1.0gives the image a name and tag..uses the current directory as the build context.
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:
-druns in the background.--name my-apigives the container a stable name.-p 3000:3000maps host port to container port.
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
docker buildcreates an image.docker runstarts a container.-p host:containerpublishes a port.docker logsis the first debugging command.docker execlets you inspect a running container.