Here is how we containerize an application in this example I have chosen a dotnetcore application.
Add a Dockerfile which will be used to create an image for your application. Below is the sample.
FROM microsoft/dotnet:2.2-sdk AS build this basically says create our application based on this Microsoft image.
Navigate the shell to your application folder and then using docker run create an image for your application.
docker build -t sampleapp.
you can see your image using docker images. Finally that you have your image ready we can create as many container we need using this.
There are two options to create a container out of the image you just created either use this below command
docker run -d -p 8080:80 --name sampleapp appcontainername
or use the docker-compose.yml file from the app folder. Which consists the exact same information as yml file. Then use
in the application folder from the shell.
now you must be able to see you web page on docker's ip and your port 8080.
Some useful docker commands
default is the docker machine's name in this example.
docker-machine regenerate-certs default
Every time our machine restarts DOCKER_MACHINE(environment variable) gets new ip and certs needs to be regenerated using this command.
will list the docker machines.
docker machine env default
will list the environment variables required for the machine.
docker-machine env default --shell bash
will get the command to run to set the environment variable using bash as shell in this sample.
eval $("C:\Users\bitsmonkey\bin\docker-machine.exe" env default --shell bash)
will set the environment variables required for docker to use this machine.
you just Containerized!!!
Photo by frank mckenna on Unsplash
Originally Posted on BitsMonkey