Container Vs VM: Docker Image
Container Vs VM: Docker Image
A container runs natively on Linux and shares the kernel of the host machine with other
containers. It runs a discrete process, taking no more memory than any other executable, making
it lightweight.
Docker Image
A Docker image contains everything it needs to run, independent of the Linux server on
which it lives: a copy of the operating system, a database, code, configuration files,
dependencies, and so on.
An image is a file that makes up just enough operating system to run a container inside it.
An image includes everything needed to run an application - the code or binary, runtimes,
dependencies, and any other filesystem objects required.
Docker Container
Fundamentally, a container is nothing but a running process, with some added encapsulation
features applied to it in order to keep it isolated from the host and from other containers.
Containers have 1 main process, which when stops, the container too stops.
One of the most important aspects of container isolation is that each container interacts with its
own private filesystem; this filesystem is provided by a Docker image.
Means - Containers are isolated from each other…if we create a container with an image and create
some new file, then the original image does not change…image will not have that file. That file will
only be visible inside that particular container.
So, If we create another container also with same image, we will not see that new file.
Docker run command takes an image and runs a container inside it as a process that does something
0685cf8d0ff9 hello-world "/hello" 37 minutes ago Exited (0) 37 minutes ago competent_moore
Container to Image
Docker exec
Detached containers – we can start a container and leave it running…this is called a detached
container. Use flag -d to specify it as a detached container when running it.
Docker run -d
We can exit the container, but the container still is running in background.
Volumes –
Volumes are like virtual disk storage, which can be shared across containers
2 types –
Persistant – permanent storage
Ephemeral – only exists till data is being used by a cotainer
Docker registry –
A registry is a piece of software that manages distribution of images, and stores metadata about
images such as tags, etc.
Hub.docker.com
Docker search
DockerFile –
Docker files are small programs that describe how to build a docker image from scratch
Each step in a docker file builds over the image created in previous step. So each line is like docker
run…creates a container of its own, saves the image and exits on next line
Processes that start on one line will not be running on the next line…each line of statement is like
a new process
Each step in docker file is cached, so docker can skip steps that are cached already and do not
need to be built again..(if anything has not been changed)
Dockerfiles describe how to assemble a private filesystem for a container, and can also contain
some metadata describing how to run a container based on this image.
FROM – specifies which image to download and start from. Must always be the first expression in
dockerfile
RUN – runs the command through the shell, waits for it to finish and saves the result
USER – Sets which user the statements in the container will run as