Containers are lightweight, portable, and self-sufficient units that encapsulate an application and its dependencies, ensuring consistent operation across environments.
Docker Compose is a tool for defining and running multi-container Docker applications. Using a docker-compose.yml file, you can define services, networks, and volumes for your application and manage them with a single command.
Docker images are immutable templates used to create containers. They contain the application code, libraries, and dependencies required to run an application.
A Dockerfile is a script containing instructions to build a Docker image. It defines the base image, application code, environment variables, and commands to run the application.
Docker networking allows containers to communicate with each other and the external world. Networks can be created and managed to isolate services for better security and performance.
Docker volumes provide persistent storage for data generated by and used by Docker containers. Volumes are stored outside the container’s lifecycle, ensuring data persists even when a container is stopped or removed.
docker start CONTAINER_ID – Start an existing container.
docker stop CONTAINER_ID – Stop a running container.
docker run [OPTIONS] IMAGE_NAME – Create and start a container from an image.
Common Options:
d – Run in detached mode.p LOCAL_PORT:CONTAINER_PORT – Port mapping.e ENV_NAME=ENV_VALUE – Set environment variables.name CONTAINER_NAME – Assign a custom name to the container.net NETWORK_NAME – Connect the container to a specific network.docker logs CONTAINER_ID – Display container logs.
docker exec [OPTIONS] CONTAINER_ID COMMAND – Execute a command inside a running container.
Common Options:
it – Interactive mode with a pseudo-TTY.