Docker Basic Commands
Youtube link: Navigation for lab
docker search nginx
// Docker images related to Nginx that are available on Docker Hub.
docker pull nginx
// This command will download the latest version of the official Nginx image from Docker Hub and make it available on your local machine for running containers. If you want a specific version of the Nginx image, you can specify the version tag after the image name.
docker images
docker run <image name>: will run the container
// Running the docker run nginx command will start a new container using the official Nginx image from Docker Hub. However, by default, this command will start the container in the foreground, which means the terminal will be attached to the container’s output, and you won’t be able to use the terminal for other commands until you stop the container.
Press Ctrl+C to exit
docker run -it nginx /bin/bash
// docker run -it nginx /bin/bash, attempts to start a new container based on the Nginx image and then launch an interactive bash shell within that container.
Exit from the console of container, Type "exit" command
docker run -d nginx
//Running the command docker run -d nginx will start a new Docker container using the official Nginx image in detached mode. This means the container will run in the background and won’t be attached to your terminal.
docker ps
//The docker ps command is used to list the currently running Docker containers on your system.
docker stop <container id/ container name>
// Absolutely, you can use the docker stop command to stop a running Docker container. You can specify either the container’s ID or its name to identify the container you want to stop.
docker rename <old name> <new name>
//Rename the container
docker restart <container id>
//restart the container
docker exec -it mynginx bash
// execute any command on the running container, name of the container or provide container id
docker logs <container id/container name>
//check the logs for running container
The docker ps -a command lists all Docker containers, both running and stopped, along with their details.
docker rm <container id/ container name>
//This will allow you to remove the stopped container
Sign-up for docker hub