Docker is an open-source platform that automates application deployment inside lightweight, portable containers. Containers package an application with all its dependencies, ensuring it runs consistently across different environments.
docker-compose.yml
file to configure the services, networks, and volumes required for an application, making it easy to manage complex applications.Setup and Teardown:
docker pull <image>
: Downloads an image from a registrydocker run <options> <image>
: Starts a new container from an image.docker stop <container-id>
: Stops a running container.docker rm <container-id>
: Deletes a stopped container.docker rmi <image>
: Deletes an image from your local machine.Working with Containers
docker ps
: Lists all running containers.docker ps -a
: Lists all containers, including stopped ones.docker logs <container-id>
: Shows the logs from a container.docker exec -it <container-id> <command>
: Runs a command in a running container.Building and Managing Images:
docker build -t <image-name> .
: Builds an image from a Dockerfile in the current directory and tags it with docker images
: Lists all images stored on your local machine.Volumes:
docker volume create <volume-name>
: Creates a new volume for persistent data.docker run -v <volume-name>:<container-path> <image>
: Attaches a volume to a container.Docker Compose:
docker-compose up
: Builds, (re)creates, starts, and attaches to containers for a multi-container application defined in a docker-compose.yml
file.docker-compose down
: Stops and removes containers, networks, volumes, and images created by docker-compose up
..dockerignore
: Exclude unnecessary files from being added to the image, similar to a .gitignore, to reduce image size and build times.