Junior — Middle
Explain the differences between Docker Container and Docker Image.
sobes.tech AI
Answer from AI
Docker Image is a template or 'snapshot' with a filesystem and settings that contains everything needed to run an application: code, libraries, dependencies, and configuration. It is a static file that does not change.
Docker Container is a running instance of a Docker Image. A container is an isolated runtime environment created from an image and can be modified during operation (for example, to save state, logs, etc.).
Example:
- Image is like a virtual machine template or a recipe.
- Container is like a running virtual machine or a finished dish prepared according to the recipe.
# Creating an image
docker build -t myapp:latest .
# Running a container from the image
docker run -d --name myapp_container myapp:latest