Building an Image

View saved

Build from the current folder

The final argument is the build context (usually .). Docker sends that context to the daemon and runs the Dockerfile.

docker build -t my-hello:1.0 .

Run your image

Use the tag you chose. Publish port 8000 so you can hit the app from the host.

docker run --rm -d --name my-hello -p 8000:8000 my-hello:1.0
curl http://localhost:8000

Rebuild after edits

Change app.py, rebuild with the same tag, then recreate the container. Old containers keep running the old image until you replace them.

docker stop my-hello
docker build -t my-hello:1.0 .
docker run --rm -d --name my-hello -p 8000:8000 my-hello:1.0

Watch layer caching

Docker reuses unchanged layers. Put rarely changing steps (install dependencies) before frequently changing ones (copy source) to speed rebuilds as projects grow.

Comments

One comment per signed-in account. Comments are saved with this page’s URL.