- Pulling an image from the repository
docker pull <name_of_the_image>
- To build an image from a Dockerfile
docker build -t <image_name> .
Note
Here .
(optional) means current folder and -t
(optional) is used to tag the image id. Both are optional.
- List all local images
docker images
- Delete an image.
docker rmi <image_name>
- Remove all unused images
docker image prune
- Publishing an image into Docker
docker push <username>/<image_name>
- Running a container
docker run -t -d -p <host_port>:<container_port> --name <name_of_the_container> <image_name>
Important
-t
tag (optional) is used to tag,
-d
detach (optional) to run in the background not to show log details and terminal detach from running container,
-p <host_port>:<container_port>
publish (optional) binding container port to the localhost.
- To open the shell inside the running container
docker exec -it <container_name> sh
- Check all the running containers
docker ps
- List the containers that ran and exited successfully.
docker ps -a
- Pings application
docker localhost
- Stops one or more running containers
docker stop
Tip
To stop all running containers
docker stop $(docker ps -q)
13.To remove a container
docker container rm
- To see how much memory using by the containers
docker stats
- Creates a tag for a target image that refers to a source image
docker tag
- Start the docker daemon
docker -d