tags: #public #docker
Why use docker?
- Same environment everywhere. No need to create seperate environment for each and every OS.
- Sandboxes the applications from each other. Makes dependeny management easy.
- Also great from a security persepctive.
- It’s very easy to start an application on docker. You can start everything in a few seconds.
Docker containers vs VM
- VMs are more resource intensive. Get’s full Operating System including the kernel
- Containers are light weight to run compared to VMs.
- Takes less disk space, memory and startup in seconds
- For example each and every VM in a system has it’s own kernel
- Containers don’t need to have a seperate kernel since all the linux distributions have the same kernel
- How does docker work in Windows?
- How does docker work in Linux?
Containers
- Running instances of an image.
- Contains OS, software, code
- Containers should be ephemeral(short lived). You should be able to create then amd distroy them anytime without lossing anything.
- Dockerfile contains step to create an image and run the application.
- You can build the image
- Then start the container
- The command mentioned in
ENTRYPOINT
would be invoked
- Volumes
- Let you share the files between containers
- As well as between the container and the host file system
- Don’t include the files in the image though.
- For that you need to COPY and build.
- Containers stop when the main process exit
- So make sure that there is only one main process per container
- Container orchastrization tools like Kubernetes are used for automating deployment, scaling and management of containarized applications.
Run
docker run -p host_port:container_port
-p
- Run in deatched mode
Kill containers
docker kill 24fe0c4ec361 3ec32a5c168a 4f447ffc0b91