Book Image

Docker Cookbook

By : Neependra Khare
Book Image

Docker Cookbook

By: Neependra Khare

Overview of this book

<p>Docker is a Linux container engine that allows you to create consistent, stable, and production-quality environments with containers.</p> <p>You will start by installing Docker and understanding and working with containers and images. You then proceed to learn about network and data management for containers. The book explores the RESTful APIs provided by Docker to perform different actions such as image/container operations. Finally, the book explores logs and troubleshooting Docker to solve issues and bottlenecks. This book will also help you understand Docker use cases, orchestration, security, ecosystems, and hosting platforms to make your applications easy to deploy, build, and collaborate on.</p>
Table of Contents (17 chapters)
Docker Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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, where we created Dockerfile to build the image:

    $ docker build . 
    

    We did not specify any repository or tag name while building the image. We can give those with the -t option as follows:

    $ docker build -t fedora/test . 
    

The preceding output is different...