Chapter

Building your own images

Write a Dockerfile and build your own images with docker build.

Docker Basics 7 Lessons from courses

About this chapter

Until now you've used images other people made. In this chapter you'll write a Dockerfile and build your own image, step by step.

Lessons from courses

  1. 1 What is a Dockerfile? What is a Dockerfile? Learn how this plain text file of instructions (FROM, RUN, COPY, CMD) becomes the recipe Docker uses to build an image.
  2. 2 Writing your first Dockerfile Write your first Dockerfile step by step using FROM, WORKDIR, COPY and CMD to package a small script into a Docker image.
  3. 3 Building and running your image Build a Docker image from your Dockerfile with docker build -t, understand the build context, then run a container from your new image.
  4. 4 RUN, COPY, WORKDIR and friends Learn the everyday Dockerfile instructions - RUN, COPY, ADD, WORKDIR and ENV - and exactly what each one does when Docker builds your image.
  5. 5 CMD vs ENTRYPOINT CMD vs ENTRYPOINT: understand the difference, how each handles arguments, and when to use CMD, ENTRYPOINT, or both together in a Dockerfile.
  6. 6 Layers and caching Learn how Docker builds images in layers, how the build cache works, and how to order Dockerfile instructions for much faster builds.
  7. 7 The .dockerignore file Learn how a .dockerignore file keeps unwanted files out of your build context for smaller, faster and safer Docker images.
Docker Basics Go to course