Build the Docker Image
After creating the Dockerfile, we can build the Docker Image using the Docker build command.
sudo docker build -t sample-image .
- sudo: This command is used to execute the subsequent command with administrative privileges. It grants the user permission to perform administrative tasks.
- docker: This is the command-line interface (CLI) tool used to interact with Docker, which is a platform for developing, shipping, and running applications inside containers.
- build: This is a Docker subcommand that is used to build an image from a Dockerfile and a context. The context is the set of files located in the specified path or directory.
- -t sample-image: The
-t
option tags the resulting image with a name. In this case,sample-image
is the name chosen for the image. This allows you to reference the image by name later on when running containers. - .: The dot (
.
) at the end of the command specifies the build context. It indicates the current directory as the build context. The build context includes all files in the current directory and its subdirectories. These files are sent to the Docker daemon during the build process.
Creating a Docker Image with Git Installed
Version control is one of the most important aspects of any software development project and when we talk about version control, there is no better tool than Git. The majority of the developers depend upon Git to manage and share their project components among the team members.
Even if you are running your project on Docker, you can still access your git account inside Docker Containers. All you need to do is just install Git inside your Docker Container. In this article, we will discuss exactly the same. We will create an Ubuntu Image, install Git inside it, create a Container associated with the Image, and verify whether Git has been installed or not.