The quantity of commands available in Docker is extensive; nonetheless, we will focus on the most prominent commands in Docker. see Docker Cheat Sheet for all Commands.
Docker Run
This command launches a container from an image. The docker run command is a mix of the docker create and docker start commands. It initiates a new container by generating one from the image that was specified. If the Docker image is not present, the Docker run will retrieve it.
docker run <image_name>
// To provide container name
docker run --name <container_name> <image_name>
Docker Pull
This commands lets you retrieve any image currently in Docker hub, the main registry of docker. It pulls the most recent image by default, but you may also specify the image version.
docker pull <image_name>
Docker PS
this command reveals a list of every running container. It allows us to utilize several flags.
- A flag displays us every container, stopped or active.
- -l flag: lets us see the most recent container.
- -q flag: displays just the Id of the containers
docker ps [options..]
Docker Stop
Stop a container if it crashed or switch to another with this command.
docker stop <container_ID>
Docker Start
This command will let you start the halted container
docker start <container_ID>
Docker rm
To remove a container through its ID or name By default, containers have IDs and fictional names. following flags can be used.
-f flag: remove the container forcefully.
-v flag: remove the volumes.
-l flag: remove the specific link mentioned.
docker rm {options} <container_name or ID>
Docker RMI
To delete the image in docker. Remove unneeded images from Docker local storage to free up space.
docker rmi <image ID/ image name>
Docker Images
Makes a list of all the images that were pulled and are in our system.
docker images
Docker exec
With this command, we can run new tasks in a container that is already running. This command does not restart after the container restarts; it only works until the container is operating. Notable flags:
- using the -d flag lets the tasks run in the background.
- With the -i flag, STDIN will stay open even when the cable is not connected.
- Sets the environment variables with the -e flag
docker exec {options}