Building images using Dockerfiles

Dockerfiles help us in automating image creation and getting precisely the same image every time we want it. The Docker builder reads instructions from a text file (a Dockerfile) and executes them one after the other in order. It can be compared as Vagrant files, which allows you to configure VMs in a predictable manner.

Getting ready

A Dockerfile with build instructions.

  • Create an empty directory:
    $ mkdir sample_image
    $ cd sample_image
    
  • Create a file named Dockerfile with the following content:
    $ cat Dockerfile
    # Pick up the base image 
    FROM fedora 
    # Add author name 
    MAINTAINER Neependra Khare 
    # Add the command to run at the start of container 
    CMD date
    

How to do it…

  1. Run the following command inside the directory, ...

Get DevOps: Puppet, Docker, and Kubernetes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.