Thuta Learning
Docker
IntermediateDevOps & ToolsIntermediate

docker build

DockerLesson 11

docker build reads your Dockerfile and builds a new image from it. This is the step where your own app gets turned into a reusable image.

dockerfile
# In the same directory as your Dockerfile
docker build -t my-custom-nginx:1.0 .

# Run the image as a container
docker run --name my-site -d -p 8080:80 my-custom-nginx:1.0

# Open http://localhost:8080 in your browser

-t my-custom-nginx:1.0 gives the image a name and tag. And at the very end, the . is the build context — it sends the Dockerfile and any needed files from the current folder into the Docker build process.

You should see
Once the build steps finish, you'll have a my-custom-nginx:1.0 image, and you'll be able to view the site in your browser.

Info

If your build context has a lot of unnecessary large files, the build can slow down. In a real project, .dockerignore should be added, and node_modules, logs, and cache files should be excluded.

Easy traps

  • Forget the trailing . and docker build won't know the context, so it'll throw an error. That little dot at the end of the command is tiny but important.

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

docker build | Thuta Learning