In this article I will be giving you an introduction about Docker.
You can watch the full video on Youtube:
So what we will cover today:
- What is Docker
- What is a Container
- What is an Image
- What is a Dockerfile
- What is a Container Registry
- Difference between Docker and VM
- Docker setup
- Will Create our first Docker image
Please like, share and subscribe if you like the video. It will really help the channel
A container Management System which allows us to package an application with all its dependency and configurations
the package which is a created can be easily moved and shared
Docker is used for automating deployment on the cloud or on-premise
Docker containers can run anywhere
- A container is a way to package an application with all of its dependency and configurations
- the package which is a created can be moved around from one machine to another or from one server to another and easily shared
- The ability to manage, package and configure a container is one of the main benefits of using docker
- All containers are based on minimal OS, mostly on Linux environment
Containers are stored in container repository it could be a private or public one
- Example of public repository is docker hub for docker container
An image is the application binary, and dependencies with the meta data on how to run it. In essence it's the binary that the application needs because the host provides a kernel. We are just starting a single file
Images derives from base images, for example if i am building a .Net application i need to have the .Net SDK image as a base image or if i am building a node app i need the nodejs image.
An image is the binaries and libraries and source code that that makes our application.
A container is a running instance of that image, we can have many containers based of the same image
It is the set of instruction that we write to build, run and configure our application inside our Docker container.
The Registry is a stateless, highly scalable server-side application that stores and lets you distribute Docker images.
Hosting all the images in one stored location allows users to commit, identify and pull images when needed.
We can build our own images and we can also get images from registries. Similar to Github, where we can find source code, Docker hub (hub.docker.com) is the registry where we can find images.
- Limited performance based on hardware virtualisation
- Every VM requires its own OS
- Higher hardware requirement for virtualisation
- App communication is harder due to App segregation
- Native performance
- Shared OS across all containers
- Runs on every machine with a modern OS
- Very easy to create networks and facilitate communication between Apps
Download it from (https://www.docker.com/products/docker-desktop)
Open an account on Docker Hub: (https://hub.docker.com/)
- docker daemon will look locally to see if the image exist
- if the image is located it creates a container and starts it
- if the image doesn't exist it will communicate with docker hub
- look for the image on docker hub
- once the image is found on docker hub, if the request doesn't specify a version of the image the latest version is selected
- it is downloaded locally to the computer
- docker daemon will create a container of this image and starts it
Open the terminal type the command below
Now we need to create an asp.net core application using the following command
dotnet new mvc -n "DockerSample"
Now we need to build the project and run it to make sure everything is working as it should
dotnet build dotnet run
As we can see the application is running, we need now to stop the application and add our Docker file. the Dockerfile will be added in the root directory of our application the D in Dockerfile must be capitalised. Once we add it we can see the whale icon.
# Get the base image FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env WORKDIR /app # Copy the csproj and restore all of the nugets COPY *.csproj ./ RUN dotnet restore # Copy everything else and build COPY . ./ RUN dotnet publish -c Release -o out # Build runtime image FROM mcr.microsoft.com/dotnet/sdk:5.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "DockerSample.dll"]
As well lets update the program.cs class to force Asp.Net Core to utilise the port 80.
Build the docker file and make sure it run
docker build -t sampledocker . docker run -p 8008:80 sampledocker