Docker container and docker image, what are they?

Joined
Apr 16, 2023
Messages
149
Reaction score
16
Credits
1,460
This is what I know about docker container and image:
Container * An instance of an image is called a container. It's a process by itself and each process has its own hostname(IP Address) like a virtual machine. * The lifecycle of the container is tied to this process. If the process ends, then the container ends. * The container or instance of a Docker image will contain the following components: * An operating system selection(for example, a Linux distro or Windows) * Files added by the developer(for example, app binaries) * Configuration(for example, environment settings and dependencies) * Instructions for what processes to run by Docker. * A container represents a runtime for a single application, process, or service. It consists of the contents of a Docker image, a runtime environment, and a standard set of instructions. * You can create, start, stop, move or delete a container using the Docker API or CLI. * Container makes it possible for each application to have its own networking stack, which means it can have its own IP address, file system. In short, its an isolated process.
Containers are created from images, which may be considered as templates for creating containers. A container may be considered as a dynamic implementation of an image, which is a static tarball containing a filesystem. Images are building blocks of containers. So, where do we get the images? One way is that we build our own images but we also have an enormous number of images available in the public registries like Docker Hub, Google Container Registry, Amazon EC2 Container Registry, Azure Container Registry, etc. When we install Docker, by default we get connected to the Docker Hub Registry.
Docker Image: * A package with all of the dependencies and information needed to create a container. An image includes all of the dependencies(such as frameworks) plus deployment and configuration to be used by a container runtime. * Usually, an image derives from multiple base images that are layers stacked one atop the other to form the container's file system. * An image is immutable after it has been created. * Docker image containers can run NATIVELY on Linux and Windows. * Windows images can run only on Windows hosts. * Linux images can run only on Linux hosts, meaning a host server of a VM. * Developers who work on Windows can create images for either Linux or Windows images.
We can consider an image as a template in a read-only format that provides us a composite filesystem for creating containers. Images are made up of multiple layers of files and directories that are stacked in a particular order, and they form the basic building block of containers. The layers that form an image are "immutable", or in other words, once the layers are generated, they can never be changed. They may be physically deleted, but they can't be modified. A container is created by adding a thin read-write layer on top of an image. This is extremely important as this opens up the possibility of creating n number of containers from a single image. The sharing of images is a fundamental concept of Docker, and this is possible through mechanisms like copy-on-write that allows containers to change layers of an image by copying it up to its read-write layer and then incorporating whatever changes it requires to make.
I was reading this blog.
https://techtutorialsite.com/docker-commit-changes-to-containers/
Where the author commited a container into an image. I didn't understand that. Can you help me realize it? How is it possible to commit a container to an image?
 


What the person is saying is once you have the image and you want to change something inside that image without rebuilding it you can use
Code:
docker commit.
to do it

What you pull from dockerhub are pre-built images.

The way you build an image is using a Dockerfile first
Here is an example of a Dockerfile
Code:
FROM debian
MAINTAINER pepdebian
RUN apt-get update
CMD ["echo", "This is my Image"]

So lets break this down.

  1. FROM – Defines the base of the image you are creating. You can start from a parent image (as in the example above) or a base image. When using a parent image, you are using an existing image on which you base a new one. Using a base image means you are starting from scratch (which is exactly how you would define it: FROM scratch).
  2. MAINTAINER – Specifies the author of the image. Here you can type in your first and/or last name (or even add an email address). You could also use the LABEL instruction to add metadata to an image.
  3. RUN – Instructions to execute a command while building an image in a layer on top of it. In this example, the system searches for repository updates once it starts building the Docker image. You can have more than one RUN instruction in a Dockerfile.
  4. CMD – There can be only one CMD instruction inside a Dockerfile. Its purpose is to provide defaults for an executing container. With it, you set a default command. The system will execute it if you run a container without specifying a command
The way you build an image from that above Dockerfile is using this command
Code:
sudo docker build -t my_first_image

Keep that in mind ...... that is the basics steps needed to build an image.....
rather than have to do that each time you need to change somethings to the images
docker commit
is used to save you time as well as it lets you debug a container by running an interactive shell, or you can export a working dataset to another computer etc..... In general Docker says it is better to use Dockerfiles to manage your images in a documented and maintainable way.
 
Last edited:
What the person is saying is once you have the image and you want to change something inside that image without rebuilding it you can use
Code:
docker commit.
to do it

What you pull from dockerhub are pre-built images.

The way you build an image is using a Dockerfile first
Here is an example of a Dockerfile
Code:
FROM debian
MAINTAINER pepdebian
RUN apt-get update
CMD ["echo", "This is my Image"]

So lets break this down.

  1. FROM – Defines the base of the image you are creating. You can start from a parent image (as in the example above) or a base image. When using a parent image, you are using an existing image on which you base a new one. Using a base image means you are starting from scratch (which is exactly how you would define it: FROM scratch).
  2. MAINTAINER – Specifies the author of the image. Here you can type in your first and/or last name (or even add an email address). You could also use the LABEL instruction to add metadata to an image.
  3. RUN – Instructions to execute a command while building an image in a layer on top of it. In this example, the system searches for repository updates once it starts building the Docker image. You can have more than one RUN instruction in a Dockerfile.
  4. CMD – There can be only one CMD instruction inside a Dockerfile. Its purpose is to provide defaults for an executing container. With it, you set a default command. The system will execute it if you run a container without specifying a command
The way you build an image from that above Dockerfile is using this command
Code:
sudo docker build -t my_first_image

Keep that in mind ...... that is the basics steps needed to build an image.....
rather than have to do that each time you need to change somethings to the images
docker commit
is used to save you time as well as it lets you debug a container by running an interactive shell, or you can export a working dataset to another computer etc..... In general Docker says it is better to use Dockerfiles to manage your images in a documented and maintainable way.
thanks for the information.
 
Newbie here but maybe this example will give you another insight.

I have been running a prebuilt image which I run with a docker run and several parameters for bind mounts, environment variables, networking etc.

I needed to change the Group ID of the user running that running docker container.

I created a snapshot of it with docker commit and used that new image, not the original, in a modified docker run command adding the --group-add 999 parameter I needed (gid=999 is the group id of the docker group on the host linux).
 

Members online


Latest posts

Top