Installing Docker And Running Container Locally

Introduction

If we want to run our web application, we should have a hosting server and on top of that, we need to buy the hardware to run our application. On the other hand, if we want to run another application, that application must have different dependencies, like OS and hardware capabilities to respond to the request. In this case, we might go for virtualization; we have to create two different virtual machines to run each of our applications. The problem here is that we should have memory allocation for each application. Also, the bootup time of the OS  is very high.

To avoid memory overhead, OS patching, and other issues, we have the Containers concept. Instead of vitalizing the hardware, we are vitalizing the OS here, i.e., container image, when we are running the application on the top the container image, the application itself will think it’s running on the dedicated server.

Docker is the platform to deploy the containers when we are deploying the .NET application. In general, we might have .dll or .exe files on the build, whereas in the container, we will have the container image that will have all the other dependencies to run our application.

Install Docker for Windows

Go to the link here or search with doc.docker in any of the search engines to get the downloaded file. After our installation, we should create Docker ID to access the docker

 

Installing Docker and Running Container Locally

 

Installing Docker and Running Container Locally
 
Step 1
 
Once the installation of the docker is done then it will be showing in the system tray.

Below are the few docker commands for reference to run the commands locally.

  1. docker run – to start a new container
  2. docker ps – to know containers' list which are running locally
  3. docker logs – to check the logs
  4. docker exec – run a specific command inside the container
  5. docker images – manages the images
  6. docker volumes - manages the volumes
  7. docker rm – removes the container
Installing Docker and Running Container Locally
 
If you want to update the application which is running inside the container, then we are deleting the container and adding a new one instead of updating the previous version. If it’s the case then what will happen to our data which is associated with the container?

That’s where docker volumes come in, which means we can be able to mount the container by using the docker commands.

Installing Redis locally

docker run –d –p 6379:6379 –name reddis redis

  • –d- running the container in the background
  • –name reddis –name of the container
  • 6379:6379 – exposing default redis port
Installing Docker and Running Container Locally

When we are running the above-mentioned command locally, then it will take some time to download the copy from redis repository, then run the docker ps command to list the containers which are running locally. In the below output we could see the status and port ,Id ,name etc.

Next run the command docker logs to know about logs of the container which were installed previously. If you know the name of the container then pass the name as parameter or pass the id as the parameter in the docker logs command.

Installing Docker and Running Container Locally
 
Installing Docker and Running Container Locally
 

Running commands inside the container

In the last command we have installed Redis locally and exposed port 6379, which means we could use the Redis CLI to connect to our container on the port 6379. Now we can run another command on the container that we are already running. What we are saying here is we want to execute the sh command , docker exec –it rediss1 sh

  • -it is running command in interactive mode
Installing Docker and Running Container Locally
 
Installing Docker and Running Container Locally


Similar Articles