Docker Elements

posted May 7, 2016, 4:20 PM by Sachchida Ojha   [ updated May 7, 2016, 4:48 PM ]
1. Docker Containers: Docker containers wrap up a piece of software in a complete file system that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in. A container is basically the actual directory on a computer which contains everything in the docker application which you are going to launch. A container is an active (or inactive if exited) stateful instantiation of an image.

2. Docker Images: Basically snapshot of a container which contains base operating systems and all iterative changes made. An image is an ordered collection of root file system changes and the corresponding execution parameters for use within a container runtime. Images are read-only.

========================================================================================
Images are frozen immutable snapshots of live containers. Containers are running (or stopped) instances of some image. Answering from a Java developer perspective, difference between a Docker Image and a Docker Container is the same as that of difference between a Java Class and an Object. In practice, Object is the runtime instance of a Class. Similarly, Container is the runtime instance of an Image. Object gets created only once it is instantiated. Similarly Container can be running or stopped. And containers are created out of an image. When using docker, we start with a base image. We boot it up, do changes and the changes are saved in layers forming another image. So eventually I have an image for my postgres and an image for my web app, changes to which keep on being persisted. Images are created with the build command, and they'll produce a container when started with run. Images are stored in a Docker registry such as registry.hub.docker.com. Because they can become quite large, images are designed to be composed of layers of other images, allowing a miminal amount of data to be sent when transferring images over the network.
========================================================================================

3. Docker Files: Docker files are scripts that automates the build process for creating an image. Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

Best practices for writing Dockerfiles

Docker can build images automatically by reading the instructions from a Dockerfile, a text file that contains all the commands, in order, needed to build a given image. Dockerfiles adhere to a specific format and use a specific set of instructions. You can learn the basics on the Dockerfile Reference page. If you’re new to writing Dockerfiles, you should start there.

Comments