Sunday, May 12, 2019

Creating First Docker Image and Contaniner

In this post we are going to see the list of following things:

1.How to create a docker Image of our .NetCore Application.
2.How to create a container for that Image and Run the Container.


I Hope you have installed(Please follow this link for docker installation) .Now go the folder where you .net core project created and create a Docker file.Docker file is a list instructions tells what need to be done when we run our container.


So this is my docker file content.My Project Structure.




Once the docker file ready.Lets create our docker image.

General Syntax to create Docker Image:

docker build -t [Name] -f Dockerfile  .

Name = It is a user given name for your docker image.

Example:

docker build -t firstcoreapp5 -f Dockerfile  .

When you run this command you can see your docker client will start to download list of packages and create a docker image.

To ensure you docker image create lets run this command "docker images".



To create container and run Type the following command

General Syntax:

docker run -d -p 8080:80 --name [Your_Container_Name] [Your_Image_Name]

Example:

docker run -d -p 8080:80 --name coreapp5 firstcoreapp5

To make sure you container is running use the following command.

Example:

docker ps 




Now open your browser and type http:\\localhost:8080 if everything is right you can see .net core project output. In my case this is my output.




Download Source Code





No comments:

Post a Comment