Docker Hub to Container : Pull , Run and Deploy Step-by-step tutorial

Pull Image from Docker Hub:
command - docker pull repositoryname/imagename
example: docker pull saifosys/saifosys:2.1.2-release
Here the first saifosys is the repository name and the second saifosys is the image name followed by :2.1.2-release the tag name.
The command docker pull saifosys/saifosys:2.1.2-release is used to download the saifosys/saifosys Docker image from Docker Hub (or another specified registry) to your local machine.
Check Images:
command – docker images
The command docker images is used to list all the Docker images available on your local machine. Here’s a breakdown of the output:
- REPOSITORY: The name of the image repository (e.g., saifosys/saifosys).
- TAG: The tag or version of the image (e.g., latest).
- IMAGE ID: A unique identifier for the image.
- CREATED: The date and time when the image was created.
- SIZE: The size of the image in bytes.
Run the downloaded Docker Image:
command - docker run --name nameforthecontainer -p (portno of host:portno of container) -d repositoryname/imagename
example: docker run --name myapp -p 8080:8080 -d saifosys/saifosys:2.1.2-release
Access the Application:
Go to your favourite browser type the url
http://localhost:8080
List the containers:
1.docker ps
- Displays only running containers.
- Shows the container ID, image, command, created time, status, ports, and names.
2.docker ps -a
- Displays all containers, including stopped ones.
- Shows the same information as docker ps, but includes stopped containers.
3.docker ps -a -q
- Displays all containers, including stopped ones, but only shows their IDs (quiet mode).
- Useful for scripting or automated tasks where you only need the container IDs.
Connect to Container Terminal:
command - docker exec -it <container-name> /bin/sh
example: docker exec -it myapp /bin/sh
When you run this command, you'll be dropped into a shell inside the myapp container, where you can execute commands, inspect the container's filesystem, and more.
Container Stop:
command - docker stop containername
example - docker stop myapp
The command docker stop containername is used to stop a running Docker container.
Container Start:
Stopping a container does not remove it. You can restart it with docker start containername.
docker start containername
example - docker start myapp
Remove Container:
- You can only remove stopped containers. If the container is running, you need to stop it first using (command - docker stop containername).
- Removing a container does not remove its image. The image will still be available locally.
Command - docker rm containername or docker rm containerid
example - docker rm myapp
Remove Image:
command - docker rmi <image-name> or
command - docker rmi <image-id>
Replace <image-name> or <image-id> with the actual name or ID of the image you want to remove.