THIS HELP TO PREPARE DOCKER AND HOW TO WORK IN DOCKER AND WHAT IS DOCKER, HOW IT IS USEFUL AND IN MARKET
Size: 850.84 KB
Language: en
Added: Jun 28, 2024
Slides: 21 pages
Slide Content
What is docker ? Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. Docker provides the ability to package and run an application in a loosely isolated environment called a container.
What can I use Docker for ? Fast, consistent delivery of your applications Responsive deployment and scaling Running more workloads on the same hardware
Important Components of Docker The Docker daemon The Docker daemon ( dockerd ) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services. The Docker client The Docker client ( docker ) is the primary way that many Docker users interact with Docker. When you use commands such as docker run , the client sends these commands to dockerd , which carries them out.
Important Components of Docker Docker registries A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default. You can even run your own private registry. Docker objects When you use Docker, you are creating and using images, containers, networks, volumes, plugins, and other objects. Images : An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization.
Important Components of Docker Containers : A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state. An image is the definition of a container. Container is the instance of an image
Containers Vs Virtual Machine Container Does not contain full operating system and therefore is much lighter and much more efficient than running virtual machine.
Getting an Image docker image pull hello-world Running Container from the image docker container run hello-world If you try to run an image which does not exists on your local then run command will pull that image for you and run it. Try to run the command below to test it. docker container run virtualpairprogrammers / fleetman -webapp
mapping port docker container run - dp 8080:8080 virtualpairprogrammers / fleetman -webapp Listing the container docker container ls Stopping a container docker container stop < initals of container Id>
Docker Hub Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default. Go to https://hub.docker.com/ and create your docker hub account
Log in to your docker hub account and look for ubuntu image
Look for the official images because they are well tested
classic vs modern command docker pull ubuntu (Classic Command) docker image pull ubuntu (Modern Command) Use modern commands inspite of using classic command because they are more verbose e.g docker image ls docker container ls
help command docker --help docker image --help : Image related commands docker container --help : Container related commands
Try docker container run ubuntu to run container you will notice that it exits quickly. This happens because ubuntu image uses the command "bin/bash" which expects to run a script. In order to connect with the terminal use the command below: docker container run -it ubuntu
Additional Commands for container docker container ls -a : this command will show stop and running containers docker container start <Initials-of-container-Id> : start a stopped container docker container rm <Initials-of-container-Id> : Removing a stopped container. You cannot remove a running container. Stop the container before attempting remove it. docker container prune : Remove all stopped containers docker container logs <Initials-of-container-Id> docker container logs -f <Initials-of-container-Id> : Follow the log further docker container exec -it <Initials-of-container-Id> bash : connect to a running container's bash shell
Exercise Run a hello-world image using docker Run virtualpairprogrammers / fleetman -webapp on port 8090 List the container and stop the container Run docker container for official ubuntu image in interactive mode Perform some linux operations on it exit from container Prune the stopped containers
Building images with commit Step 1 : docker container run -it ubuntu Step 2 : apt-get update Step 3 : apt-get install -y openjdk-8-jdk Step 4 : javac (To confirm the installation of jdk ) Step 5: exit (Exit the container) Step 6 : docker container ls -a (List the containers to find out the one which you have create recently with Java installation)
Building images with commit Step 7 : docker container commit -a "<Author-name>" <Initials-of-container-Id> myjdkimage Step 8 : docker image ls (To view your the newly created image) Step 9: docker container run -it myjdkimage (Run the image which you have created previously and check if the Java is installed in it)
Docker File Committing is not thought to be a good way to create a docker image because after some time of creating image it might be hard for you to recall what is there in that image. Better way of creating docker image is by using a docker file.