Virtualization Flashcards
What is virtual Machine and Virtualisation?
https://www.redhat.com/en/topics/virtualization/what-is-virtualization
Difference between Docker containers and VMs
https: //www.youtube.com/watch?v=TvnZTi_gaNc
https: //blog.cherryservers.com/docker-containers-vs.-virtual-machines-know-the-differences#:~:text=The%20Docker%20container%20sits%20on,the%20components%20being%20read%2Donly.
Docker Terminologies
Images - The blueprints of our application which form the basis of containers. In the demo above, we used the docker pull command to download the busybox image.
Containers - Created from Docker images and run the actual application. We create a container using docker run which we did using the busybox image that we downloaded. A list of running containers can be seen using the docker ps command.
Docker Daemon - The background service running on the host that manages building, running and distributing Docker containers. The daemon is the process that runs in the operating system which clients talk to.
Docker Client - The command line tool that allows the user to interact with the daemon. More generally, there can be other forms of clients too - such as Kitematic which provide a GUI to the users.
Docker Hub - A registry of Docker images. You can think of the registry as a directory of all available Docker images. If required, one can host their own Docker registries and can use them for pulling images.
Docker commands
docker ps - list all images
docker pull
docker run
docker run -it sh = interactive mode
docker run –help
docker ps -a
docker rm 305297d7a235(CONTAINERiD)
docker container prune = remove all stopped containers
docker rm $(docker ps -a -q -f status=exited) [Remove docker containers which have status as exited – q stands for numeric ids to be returned, -f stands for filter to be applied]
docker run ImageName –rm
docker run -d -P –name static-site prakhar1989/static-site ( -d stands for it will detach terminal - even if you close terminal, it wont get closed.. )
-P will publish all exposed ports to random ports and finally –name corresponds to a name we want to give
docker port static-site
docker run -p 8888:80 prakhar1989/static-site
Types of images:
Base images are images that have no parent image, usually images with an OS like ubuntu, busybox or debian.
Child images are images that build on base images and add additional functionality.
Then there are official and user images, which can be both base and child images.
Official images are images that are officially maintained and supported by the folks at Docker. These are typically one word long. In the list of images above, the python, ubuntu, busybox and hello-world images are official images.
User images are images created and shared by users like you and me. They build on base images and add additional functionality. Typically, these are formatted as user/image-name.
Dockerfile for python application
FROM python:3
# set a directory for the app WORKDIR /usr/src/app
# copy all the files to the container COPY . .
# install dependencies RUN pip install --no-cache-dir -r requirements.txt
# define the port number the container should expose EXPOSE 5000
# run the command CMD ["python", "./app.py"]
building image
docker build -t yourusername/catnip
docker run -p 8888:5000 yourusername/catnip
The command we just ran used port 5000 for the server inside the container and exposed this externally on port 8888. Head over to the URL with port 8888, where your app should be live.
DOCKER Repository and DOcker Registry difference
Docker hub is a registry
A Docker repository is where you can store 1 or more versions of a specific Docker image. An image can have 1 or more versions (tags).
A Docker image can be compared to a git repo. A git repo can be hosted inside of a GitHub repository, but it could also be hosted on Gitlab, BitBucket or your own git repo hosting service. It could also sit on your development box and not be hosted anywhere.
The same goes for a Docker image. You can choose to not push it anywhere, but you could also push it to the Docker Hub which is both a public and private service for hosting Docker repositories. There are other third party repository hosting services too.
The thing to remember here is a Docker repository is a place for you to publish and access your Docker images. Just like GitHub is a place for you to publish and access your git repos.
It’s also worth pointing out that the Docker Hub and other third party repository hosting services are called “registries”. A registry stores a collection of repositories.
You could say a registry has many repositories and a repository has many different versions of the same image which are individually versioned with tags.
Docker push image to a registry
docker login
To publish, just type the below command remembering to replace the name of the image tag above with yours. It is important to have the format of yourusername/image_name so that the client knows where to publish.
$ docker push yourusername/catnip
Now that your image is online, anyone who has docker installed can play with your app by typing just a single command.
$ docker run -p 8888:5000 yourusername/catnip
docker network ls
listing docker network
create network in docker
Since the bridge network is shared by every container by default, this method is not secure. How do we isolate our network?
The good news that Docker has a great answer to our questions. It allows us to define our own networks while keeping them isolated using the docker network command.
docker network inspect foodtrucks-net
checking whats in foodtrucks-net network
Basic commands to create a network of containers
# build the flask container docker build -t prakhar1989/foodtrucks-web .
# create the network docker network create foodtrucks-net
# start the ES container docker run -d --name es --net foodtrucks-net -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2
# start the flask app container docker run -d --net foodtrucks-net -p 5000:5000 --name foodtrucks-web prakhar1989/foodtrucks-web
Some Definitions
Docker Machine - Create Docker hosts on your computer, on cloud providers, and inside your own data center
Docker Compose - A tool for defining and running multi-container Docker applications.
Docker Swarm - A native clustering solution for Docker
Kubernetes - Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.