Run the Docker Container
After you have built the Image, you can run the Container associated with the Image, using the Docker Run command.
sudo docker run -it sample-image bash
- sudo: This command is used to execute subsequent commands with superuser privileges. Docker typically requires superuser privileges to run, hence the use of
sudo
. - docker: This is the command-line interface (CLI) tool used to interact with the Docker daemon. It allows you to build, manage, and run Docker containers.
- run: This subcommand is used to run a command in a new container.
- -it: These are two separate options combined together.
- The
-i
option stands for “interactive” and keeps STDIN open even if not attached. - The
-t
option allocates a pseudo-TTY, which allows you to interact with the container through a terminal interface.
Together,
-it
makes the container run in an interactive mode, allowing you to input commands and see their output as if you were directly using the terminal inside the container. - The
- sample-image: This is the name of the Docker image you want to run a container from. In our case, it’s the image we built earlier, named “sample-image”.
- bash: This is the command to execute inside the container. In this case, we’re telling Docker to run the Bash shell within the container. This will give you a shell prompt inside the container, allowing you to interact with it and execute commands.
The above command creates and runs a Container and fires up the bash of the Docker Container.
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.