Assignment No - 4 - Docker
Assignment No - 4 - Docker
Title: create a VM using Docker and write your own docker file and publish it.
References : https://docs.docker.com/get-started/overview/
What is Docker:
Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in
packages called containers. Containers are isolated from one another and bundle their own software, libraries and
configuration files; they can communicate with each other through well-defined channels. All containers are run by a
single operating system kernel and therefore use fewer resources than virtual machines.
Your developers write code locally and share their work with their colleagues using Docker containers.
They use Docker to push their applications into a test environment and execute automated and manual tests.
When developers find bugs, they can fix them in the development environment and redeploy them to the test
environment for testing and validation.
When testing is complete, getting the fix to the customer is as simple as pushing the updated image to the
production environment.
Docker’s container-based platform allows for highly portable workloads. Docker containers can run on a developer’s
local laptop, on physical or virtual machines in a data center, on cloud providers, or in a mixture of environments.
Docker’s portability and lightweight nature also make it easy to dynamically manage workloads, scaling up or tearing
down applications and services as business needs dictate, in near real time.
Docker is lightweight and fast. It provides a viable, cost-effective alternative to hypervisor-based virtual machines, so
you can use more of your compute capacity to achieve your business goals. Docker is perfect for high density
environments and for small and medium deployments where you need to do more with fewer resources.
Docker Architecture / Docker Engine
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.
When you use the docker pull or docker run commands, the required images are pulled from your configured
registry. When you use the docker push command, your image is pushed to your configured registry.
Docker objects
When you use Docker, you are creating and using images, containers, networks, volumes, plugins, and other objects.
This section is a brief overview of some of those 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. For example, you may build an image which is based on the ubuntu
image, but installs the Apache web server and your application, as well as the configuration details needed to make your
application run.
You might create your own images or you might only use those created by others and published in a registry. To build
your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run
it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image,
only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast,
when compared to other virtualization technologies.
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.
Step1: Begore staring isntallation remove the old installation if any, by using command:
$ sudo apt-get remove docker docker-engine docker.io containerd runc
Step 2: update the packages by using command:
sudo apt-get update
fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching
for the last 8 characters of the fingerprint.
Step 6:
Use the
following command to set up the stable repository. To add the nightly or test repository, add the
word nightly or test (or both) after the word stable in the commands below.
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
Install Docker Engine
Step 7: Update the apt package index, and install the latest version of
Docker Engine and containerd, or go to the next step to install a
specific version:
Docker Compose
Compose is a tool for defining and running multi-container Docker applications.
With Compose, you use a YAML file to configure your application’s services.
Then, with a single command, you create and start all the services from your
configuration. To learn more about all the features of Compose, see the list of
features.
Compose works in all environments: production, staging, development, testing, as well as CI workflows. You can learn
more about each case in Common Use Cases.
3. Run docker-compose up and Compose starts and runs your entire app
Docker Desktop
Docker Desktop is an easy-to-install application for your Mac or Windows
environment that enables you to build and share containerized applications and
microservices. Docker Desktop includes Docker Engine, Docker CLI client, Docker
Compose, Notary, Kubernetes, and Credential Helper.
Commands
1) docker -v
2) docker info - Display system-wide information
docker ps [OPTIONS]
2) search “image name” in search box (I have searched for nginx image)
3) open the image link
-t => terminal
Docker Hub
Ref: https://docs.docker.com/docker-hub/
Docker Hub is a service provided by Docker for finding and sharing container
images with your team. It provides the following major features:
Repositories: Push and pull container images.
Teams & Organizations: Manage access to private repositories of container images.
Official Images: Pull and use high-quality container images provided by Docker.
Publisher Images: Pull and use high- quality container images provided by external vendors.
Builds: Automatically build container images from GitHub and Bitbucket and push them to Docker Hub.
Webhooks: Trigger actions after a successful push to a repository to integrate Docker Hub with other services.
1. Open your browser and navigate to http://localhost:8081 to make sure our html page is being served
correctly
4.To stop container gracefully: docker-compose stop