-
docker run: Used to create and start a container.
- Example:
docker run hello-world
runs a container from the "hello-world" image. - Example:
docker run -it ubuntu bash
runs an Ubuntu container and opens a bash shell.
- Example:
-
docker ps: Lists running containers.
- Example:
docker ps
shows all currently running containers.
- Example:
-
docker ps -a: Lists all containers, both running and stopped.
- Example:
docker ps -a
- Example:
-
docker images: Shows a list of all images on the local system.
- Example:
docker images
- Example:
-
docker pull: Pulls an image from a Docker registry.
- Example:
docker pull nginx
pulls the Nginx image from Docker Hub.
- Example:
-
docker build: Builds a Docker image from a Dockerfile.
- Example:
docker build -t my-image .
builds an image with the tag "my-image" from the current directory.
- Example:
-
docker exec: Runs a command in a running container.
- Example:
docker exec -it my-container bash
opens a bash shell inside "my-container".
- Example:
-
docker stop: Stops a running container.
- Example:
docker stop my-container
- Example:
-
docker start: Starts a stopped container.
- Example:
docker start my-container
- Example:
-
docker rm: Removes a container.
- Example:
docker rm my-container
- Example:
-
docker rmi: Removes an image.
- Example:
docker rmi my-image
- Example:
-
docker logs: Shows logs for a container.
- Example:
docker logs my-container
- Example:
-
docker network: Manages networks.
- Example:
docker network ls
lists all Docker networks.
- Example:
-
docker volume: Manages volumes.
- Example:
docker volume ls
lists all Docker volumes.
- Example:
-
docker-compose: Used to define and run multi-container Docker applications.
- Example:
docker-compose up
starts the services defined indocker-compose.yml
. - Example:
docker-compose down
stops the services started bydocker-compose up
.
- Example:
These commands cover the basics of interacting with Docker, including managing containers, images, networks, and volumes. For more detailed information and examples, refer to the official Docker documentation.