Docker

How to Run Docker Image From Local Repository?

Docker images are packaged sets of software and its dependencies that are designed to execute Docker containers. Docker images are built from the Docker file that has instructions for building/creating Docker images. They can be stored in a local repository on the user’s machine or can be stored on Docker Hub.

This write-up will explain the method to run a Docker image from the local repository.

How to Run Docker Image From Local Repository?

To run the Docker image from the local repository, check out the following steps:

    • Display all Docker images.
    • Select desired Docker image.
    • Run the Docker image to build a container using the “docker run –name <container-name> -p <port-no> <image-name>” command.

Step 1: List Docker Images

First, display all the Docker images and choose the particular image:

docker images

 
The below output displays all the Docker images and we have selected the “linuximg” image:


Step 2: Run Docker Image

Then, run the Docker image to build a Docker container using the provided command:

docker run --name imgcont -p 80:80 linuximg

 
Here:

    • –name” is used to define the container name.
    • imgcont” is the name of the container.
    • -p” is utilized to assign the port to the container.
    • 80:80” is the assigned port.
    • linuximg” is the Docker image:

 

Step 3: Verification

For verification check out if the container is executing by its image or not:

docker ps -a

 
It can be seen that the Docker container is running by its Docker image:


That was all about running Docker Image from the local repository.

Conclusion

To run a Docker image from the local repository, first, list all the images of the local repository and choose the particular image. Then, run the selected Docker image to build a container using the “docker run –name <container-name> -p <port-no> <image-name>” command. Lastly, check the running container with its image via the “docker ps -a” command. This write-up explained the method to run a Docker image.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.