Debug School

rakesh kumar
rakesh kumar

Posted on

Explain the difference between docker pull,create,run and build commands

Image description

docker create httpd:

docker create httpd
docker create --name raj1 httpd
Enter fullscreen mode Exit fullscreen mode

Explanation:
This command creates a new Docker container from the httpd image but does not start it. The container is in a "created" state.
The docker create command is used when you want to create a container but delay its execution until later. You would need to use docker start separately to run the container.
2. docker pull httpd:

docker pull httpd
Enter fullscreen mode Exit fullscreen mode

Explanation:
This command pulls the httpd image from the Docker Hub to your local machine.
The docker pull command is used to download a Docker image from a registry (by default, it pulls from Docker Hub) to your local Docker environment.
Pulling an image doesn't create or run a container. It simply fetches the image so that it's available locally for running containers.
3. docker run httpd:

docker run httpd
Enter fullscreen mode Exit fullscreen mode

Explanation:
This command both creates and starts a new container from the httpd image.
If the httpd image is not available locally, it automatically pulls it from Docker Hub before creating and running the container.
The docker run command is a combination of docker create and docker start. It creates a new container and starts it in one step.
4. docker build httpd:
Explanation:

If you have a Dockerfile for the httpd image, you would navigate to the directory containing the Dockerfile and run:

docker build -t my-httpd-image 
Enter fullscreen mode Exit fullscreen mode

This command builds a Docker image named my-httpd-image using the Dockerfile in the current directory (.).
Summary:
docker create httpd:

Creates a container from the httpd image but doesn't start it. You need to use docker start separately.
docker pull httpd:

Pulls the httpd image from the Docker Hub to your local machine. It doesn't create or run a container.
docker run httpd:

Creates and starts a container from the httpd image. If the image is not available locally, it automatically pulls it before creating and running the container.
docker build httpd:

Builds a Docker image from a Dockerfile. It's used for creating a custom image based on instructions in a Dockerfile.

Top comments (0)