DEV Community

Anass Assim
Anass Assim

Posted on

📝 Docker Images Cheat Sheet 🚀

Command Description
docker pull nginx Pulls the latest Nginx image from Docker Hub.
docker images Lists all Docker images on the local machine.
docker ps Lists all running containers.
docker run -d nginx:latest Runs an Nginx container in detached mode using the latest version.
docker run -d -p 8080:80 nginx:latest Runs Nginx in detached mode and maps port 8080 on the host to port 80 in the container.
docker run -d -p 8080:80 -p 3000:80 nginx:latest Runs Nginx in detached mode and maps multiple ports (8080 and 3000).
docker ps -a Lists all containers (including stopped ones).
docker exec -it $ID Executes a command inside a running container (replace $ID with container ID).
docker rm $(docker ps -aq) Removes all stopped containers.
docker run --name "MyPage" -d -p 8080:80 nginx:latest Runs a container named "MyPage" with port mapping.
cd /home/user/myhtml && docker run --name "MyPage" -v $(pwd):/usr/share/nginx/html:ro -d -p 8080:80 nginx Runs a container and mounts the local HTML folder to the container.
docker exec -it $container_name bash Opens a bash shell in the running container (replace $container_name).
docker run --name "copy-of-mypage" --volumes-from "mypage" -d -p 8081:80 nginx Runs a new container using the same volumes as "mypage" and maps port 8081.

Top comments (0)