Docker Run Image
Docker images are the essential component of the Docker environment. A Docker image includes instructions for Docker containers. These instructions tell the container how to manage and deploy the application. Docker images are usually made by Dockerfile, which is a set of commands used to build and run Docker images.
This blog will demonstrate how to run a Docker image using the “docker run <image-name>” command.
How to Run Docker Image?
The Docker “run” command is utilized to run images. For this purpose, first, create a simple Dockerfile. Then, build a new Docker image and run the image using the “docker run <image>” command.
Look at the given instructions to execute the Docker image.
Step 1: Create Program File
Create a simple Python program file as “Tutorial.py”. The specified program will display the “Hello, Welcome to Linuxhint Tutorial” message on the console or terminal:
Step 2: Create Dockerfile
Next, create a new file named “Dockerfile” and paste the following piece of code into the file:
Step 3: Built Docker Image
Next, build the new Docker image using “Dockerfile”. To do so, check out the mentioned command. Here, the “-t” flag is specifying the image name:
Move toward the next step for verification.
Step 4: List Images
List down all Docker images to verify if the new image is created or not:
The output shows that the image has been successfully created from Dockerfile:
Step 5: Run Image
Now, run the Docker image through the “docker run <image-name>” command. This command will automatically build and run the container for program deployment:
Here, you can see we have successfully deployed a simple “Tutorial.py” Python program using Docker image:
We have taught you how to run Docker images using the “docker run image” command.
To run the Docker image, first, create a simple Dockerfile. Next, to build an image, utilize the “docker build” command. After that, execute the Docker image with the help of the “docker run <image-name>” command. The blog has demonstrated how to run the Docker image using the “docker run image” command.