Docker Flashcards
What is a container?
A container is an isolated unit of software that is based on an image. It is a running instance of that image.
What is Docker?
Docker is a container technology for creating and managing containers.
Docker allows us to have the same exact environment for development and production.
What is an Image?
A file used to execute code in a Docker container. Holds all the logic and code a container needs.
Steps to create own our docker image
- Base on default image (FROM)
- Set work directory folder
- Copy code
- Run commands (npm install)
- Expose port for Docker
- Run commands when container is started
Command to create the image
docker build [path]
Command to run an image as a container
docker run [image name/id]
Command to stop a container
docker stop [image name/id]
Are images read only?
Yes, once an image is built, it is locked in
What image layers are changed after finding a change in an image when rebuilding?
All layers after the changing layer are rebuilt
Why do we have images and containers? Why not just containers?
This allows multiple containers to be based on the same image without interfering with each other
What are layers in the context of images?
Every instruction in an image creates a cacheable layer. Layers help with image rebuilding and sharing
Difference between detached and attached mode
In detached mode, the container runs in the background of your terminal. It does not receive input or display output.
In attached mode, it can attach the console to the process’s output
Command to remove containers/image
Containers: docker rm [container name]
Images: docker rmi [image id]
Remove all stopped containers: docker container prune
Remove all unused images: docker image prune
What is a DockerFile?
It is a text file that has all commands which need to be run for building a given image
What is Docker Compose?
Docker-compose is used for creating multiple containers, hosting them and establish communication between them