What is the difference between a Docker image and

2019-01-04 15:33发布

When using Docker, we start with a base image. We boot it up, create changes and those changes are saved in layers forming another image.

So eventually I have an image for my PostgreSQL instance and an image for my web application, changes to which keep on being persisted.

So the question is: What is a container?

20条回答
何必那么认真
2楼-- · 2019-01-04 15:45

Image is an equivalent to a class definition in OOP and layers are different methods and properties of that class.

Container is the actual instantiation of the image just like how an object is an instantiation or an instance of a class.

查看更多
放我归山
3楼-- · 2019-01-04 15:47

An instance of an image is called a container. You have an image, which is a set of layers as you describe. If you start this image, you have a running container of this image. You can have many running containers of the same image.

You can see all your images with docker images whereas you can see your running containers with docker ps (and you can see all containers with docker ps -a).

So a running instance of an image is a container.

查看更多
男人必须洒脱
4楼-- · 2019-01-04 15:47

In easy words.

Images -

The file system and configuration(read-only) application which is used to create containers. More detail.

Containers -

These are running instances of Docker images. Containers run the actual applications. A container includes an application and all of its dependencies. It shares the kernel with other containers and runs as an isolated process in user space on the host OS. More detail.


Other important terms to notice:


Docker daemon -

The background service running on the host that manages the building, running and distributing Docker containers.

Docker client -

The command line tool that allows the user to interact with the Docker daemon.

Docker Store -

Store is, among other things, a registry of Docker images. You can think of the registry as a directory of all available Docker images.

A picture is worth a thousand words.

Enter image description here

(For deeper understanding please read this.)

Summary:

  • Pull image from Docker hub or build from a Dockerfile => Gives a Docker image (not editable).
  • Run the image (docker run image_name:tag_name) => Gives a running Image i.e. container (editable)
查看更多
Rolldiameter
5楼-- · 2019-01-04 15:49

As in the programming aspect,

Image is a source code.

When source code is compiled and build, it is called as application.

Simillar to that "when instance is created for the image", it is called as "Container"

查看更多
干净又极端
6楼-- · 2019-01-04 15:50

Dockerfile is like your bash script that produce a tarball (Docker image).

Docker containers is like extracted version of the tarball. You can have as many copies as you like in different folders (the containers)

查看更多
虎瘦雄心在
7楼-- · 2019-01-04 15:51

The core concept of docker is to make it easy to create "machines" which in this case can be considered containers. The container aids in reusability, allowing you to create and drop containers with ease.

Images depict the state of a container at every point in time. So the basic workflow is:

  1. create an image
  2. start a container
  3. make changes to the container
  4. save the container back as an image
查看更多
登录 后发表回答