In this post i will show you how to build your first application using docker, without docker if you need to programming using language first you should install that language on your PC and test it on your development environment and for sure the production should be ready to sync and test your code again on it seems a lot of work.😥
But now with docker you just pull/grab that image, no installation needed, and run your code on that image.🎉
But how we can control what happening inside the environment, like Accessing to resources like networking interfaces and disk drives is virtualized inside this environment which is isolated from the rest of your system all of this happening by something called Dockerfile.
The Following example taken from Docker Documentation:
pip install pypi.python.org requirements.txt
As you see from the above example the code explained in the comment part, which is done by Python programming language, the above docker file create directory, copy ,paste and check the port then run the app.py.
app.py (very simple Code )
Now you have the dockerfile under the directory and the app.py file, then run the build command. This creates a Docker image,
docker build -t test .
$ docker image ls
Run the app, mapping your machine’s port 4000 to the container’s published port 80 using -p:
docker run -p 4000:80 test
Once the above command will be run the log will indicates that you could test your code using this link http://localhost:80 but this is only from inside docker, so in case you need to test it outside the docker the port will be http://localhost:4000