Docker CLI Understanding Exercise
Hello World:
Run the hello-world image on Docker Terminal. It will pull the hello-world image from the Docker Hub.
docker run hello-world
Running a Container:
Pull and run the nginx server. Once the image pulls, it executes and the nginx server starts.
docker run -d -p 8080:80 nginx
Listing Containers:
List all the running Docker containers.
docker ps
Stopping a Container:
Find the container ID you want to stop from the
docker ps
command then, stop a running Docker container using that ID.docker stop container_id
Removing Container:
Remove a Docker Container. Make sure the container is stopped before trying to remove it.
docker rm container_id
Pulling an Image:
Pull the latest Ubuntu image from Docker Hub.
docker pull ubuntu:latest
Listing Images:
List all Docker images present on your system.
docker images
Docker Run and Exec:
- Run an Ubuntu container and execute the bash command to access the Ubuntu bash Terminal.
docker run -it ubuntu bash
Build Docker Image:
Create a Dockerfile with an application. Build a Docker image from that Dockerfile.
bashtouch Dockerfile# Write your application into Dockerfiledocker build -t myapp .
Push Docker Image:
- Login to DockerHub, tag the image and push your Docker image to Docker Hub. Change
username
,image_name
andimage_id
with your DockerHub username, desired image name and ID of the created image.
bashdocker logindocker tag image_id username/image_namedocker push username/image_name- Login to DockerHub, tag the image and push your Docker image to Docker Hub. Change
By doing these exercises, you will solidify your understanding of the basic commands available in Docker CLI.