Images:
The file system and configuration(read-only) application which is used to create containers. More detail.
Containers
These are running instances of Docker images.
Docker daemon -
The background service running on the host that manages the building, running and distributing Docker containers.
Docker client -
The command line tool that allows the user to interact with the Docker daemon.
Docker Store
Store is, among other things, a registry of Docker images. You can think of the registry as a directory of all available Docker images.
image and container according to OOP
An image is to a class as a container to an object.
A container is an instance of an image as an object is an instance of a class
image is read only: how do we chagne it
-- we dont directly
-- we create new image from that images
-- we make changes to that containers
-- when we are statisfied with this chagnes, then we transform them into new layer
-- a new image is create by stacking the new layer on the top of the old image
image can be created by docker commit and docker build and docker import
Docker commands:
- docker images
- docker rmi image_name
- docker images -q
- docker ps /docker ps -a
- docker ps -a -q //only show id
- docker start/stop/restart/kill/pause
- docker rm container_name
- Docker search Ubuntu -s 5
- docker run -it <image name or image id> /bin/bash
- docker run -it ubuntu /bin/bash //create ubuntu container and open a bas
- exit //exit command to out from the bash
docker build -t my_image dir_with_dockerfile (Build Dockerfile: )docker-machine ipdocker versiondocker info
docker container run my_image — Create a new container and start it. It also has a lot of options. Let’s look at a few.docker container run -i -t -p 1000:8000 --rm my_image-i is short for --interactive. Keep STDIN open even if unattached.-tis short for--tty. Allocates a pseudo terminal that connects your terminal with the container’s STDIN and STDOUT.
You need to specify both
-i and -t to then interact with the container through your terminal shell.-p is short for --port. The port is the interface with the outside world.1000:8000
maps the Docker port 8000 to port 1000 on your machine. If you had an
app that output something to the browser you could then navigate your
browser to localhost:1000 and see it.Difference between virtual machine implementation and container based implementation
Docker Compose
Docker Compose is used to run multiple containers as a single service. For example, suppose you had an application which required NGNIX and MySQL, you could create one file which would start both the containers as a service without the need to start each one separately.What is Docker Compose
Most projects build architectures that involve more that one architecture component. Even the simplest hobby project will probably be built with a database and an application server of some kind. For example, the popular Wordpress stack consists of a Wordpress installation and a MySQL database instance.If your application needs multiple components, i.e. multiple containers for differenct purposes, you need some tool to define the containers involved in your application stack and how these containers work together.
I don’t want to make this article confusing for beginners, so we’ll stay with the below definition for the first example and we’ll add more details later in this post:
Docker Compose is the toolkit provided by Docker to build, ship and run multi-container applicatoins.
compose Ref:
- https://takacsmark.com/docker-compose-tutorial-beginners-by-example-basics/
- https://www.linode.com/docs/applications/containers/how-to-use-docker-compose/
- https://tecadmin.net/tutorial/docker/docker-compose/ (VVI)
****************************************
docker <management command> command
ex docker container run
prev docker run
docker container run --publish 80:80 nginx
docker container run --publish 80:80 --detach nginx //fro detach nginx run in background
docker container top // process list in one container
docker container inspect //detail of one container configs
docker container stats // performance stat of all container
Doker interview question:
https://www.educba.com/docker-interview-questions/
References:
- https://stackoverflow.com/questions/23735149/what-is-the-difference-between-a-docker-image-and-a-container
- https://www.youtube.com/watch?v=DgoKjlDteEA&list=PLea0WJq13cnDsF4MrbNaw3b4jI0GT9yKt (VVI)
- https://www.tutorialspoint.com/docker/
- https://towardsdatascience.com/15-docker-commands-you-should-know-970ea5203421
- https://tecadmin.net/tutorial/docker/docker-introduction/ (VVI)
- https://www.udemy.com/docker-mastery/ (good online udemy course)

