Create your own hello-world image in Docker
Hi everyone, this is a short and first tutorial on how we can create images for our application in a docker.
I made a repo on Github, I’ll upload all images on this repo, you can check it from here
- Write Dockerfile
- Build the image
- Run the image
Docker has changed the way we build, package, and deploy applications. But this concept of packaging apps in containers isn’t new — it was in existence long before Docker.
Docker just made container technology easy for people to use. This is why Docker is a must-have in most development workflows today. Most likely, your dream company is using Docker right now.
Docker’s official documentation has a lot of moving parts. Honestly, it can be overwhelming at first. You could find yourself needing to glean information here and there to build that Docker image you’ve always wanted to build.
So that’s why I decided to make a series of articles on how to build images in docker for our applications, this is the first tutorial and I know for some people it’s so easy but we’ll do a lot of advanced images later.
Write docker file
Docker builds images automatically by reading the instructions from a Dockerfile. It is a text file that contains all commands needed to build a given image. In this example, we will build and run the Hello-world image.
firstly, create a dir with any name you want then create a file called
Dockerfile without any extension, please note you should write the file as I wrote the D character should be uppercase, then copy the following code in your file.
Let’s break that code down.
- From alpine is a minimal Docker image based on Alpine Linux with a complete package index and only 5 MB in size.
- CMD: to execute the command once you run the docker container.
Build the image
Now that you have created a Dockerfile, it’s time to build your image using the
docker build command.
docker build -t helloworld-custom .
- t/ — tag gives a tag for your image
Run the image
now we built our image so let’s test it by running it.
We’ll run the image by tag that we specified in the previous command
docker container run helloworld-custom
Docker is a powerful platform for building, managing, and running containerized applications. In this Docker tutorial, we learned how to build our own image, it’ll be other tutorials learn you how to dockerize your application that works with different technologies (nodeJs - Angular - Laravel - etc..).
And that brings us to the end! Thank you so much for reading through this — if this article was helpful in any sense I’d really appreciate a follow to help me reach my 100-follower goal by the end of May 🙂.