BASH Programming

How Can I Run Bash in a New Container of a Docker Image

Docker is a popular platform for running and building applications using containers, they make it easy to run them on different platforms and environments. Running a bash in a new container is useful as it isolates the environment in which you run the bash from another environment. It allows users to set a fresh environment with no existing dependencies or configurations. This article will explain opening a new container to run Docker image in bash.

Running Bash in a New Container of a Docker Image

Before we begin, make sure that Docker is installed on your system, further to download and install Docker on Linux read this full guide.

To run bash in a new container of a Docker image, you can use the docker run command along with the name of the application image file and the command to run in the container, here is the syntax for it:

docker run -it <image-name> /bin/bash

In the above command, the -it option is used to open an interactive shell in the container and the <image-name> parameter specifies the name of the Docker image you want to run. Finally, the /bin/bash command tells Docker to run the Bash shell in the container, so if you want to run bash in a new container of the OpenJDK image, you can use the following command:

sudo docker run -it openjdk /bin/bash

The above command will start a new container based on the OpenJDK image and open an interactive Bash shell in the container, also if the application image file is not present on your system, then it will download it automatically and for further assistance on the image files click here:


Docker containers provide an easy way to package and distribute applications with their dependencies, making them ideal for building, shipping, and running applications in different environments. Using the docker run command with the appropriate options and parameters, you can create a new container of a Docker image and run Bash or any other command in the container. With Docker, you can quickly and easily run applications in isolated environments, without having to worry about the underlying system configuration.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.