Introduction to Docker
Docker is an open-source platform that automates the deployment of applications inside software containers. This ensures that the software behaves the same way, regardless of where it is deployed. Docker achieves this by combining a lightweight container runtime with workflows and tooling that help manage and deploy applications.
Core Concepts of Docker
1. Docker Images A Docker image is a lightweight, standalone, executable package that includes everything needed to run a piece of software, including the code, runtime, libraries, environment variables, and config files.
Example Command: To pull an existing image from Docker Hub:
basdocker pull ubuntu
2. Docker Containers A container is a runtime instance of an image—what the image becomes in memory when executed.
Example Command:
To run a container from the ubuntu
image:
basdocker run -it ubuntu
3. Dockerfile A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
Example Command: Creating a simple Dockerfile:
DockerfileFROM ubuntu RUN apt-get update && apt-get install -y nginx CMD ["nginx", "-g", "daemon off;"]
4. Docker Compose Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services.
Example Command: To start up a project using docker-compose:
basdocker-compose up
5. Docker Hub Docker Hub is a service provided by Docker for finding and sharing container images with your team. It is a public registry that contains a large number of images available for use.
Example Command: To login to Docker Hub:
bashdocker login
Common Docker Commands and Their Usage
Command | Description | Example Usage |
---|---|---|
docker pull | Pulls an image from a registry | docker pull ubuntu |
docker build | Builds an image from a Dockerfile | docker build -t myimage . |
docker run | Runs a command in a new container | docker run -it ubuntu bash |
docker push | Pushes an image to a registry | docker push myimage |
docker exec | Runs a command in a running container | docker exec -it mycontainer bash |
docker stop | Stops one or more running containers | docker stop mycontainer |
docker start | Starts one or more stopped containers | docker start mycontainer |
docker rm | Removes one or more containers | docker rm mycontainer |
docker rmi | Removes one or more images | docker rmi myimage |
docker logs | Fetches logs of a container | docker logs mycontainer |
docker inspect | Returns low-level information on Docker objects | docker inspect mycontainer |
docker network create | Creates a new network | docker network create mynetwork |
docker volume create | Creates a volume for persistent data storage | docker volume create myvolume |
docker compose up | Builds, (re)creates, starts, and attaches to containers | docker-compose up |
docker compose down | Stops containers and removes containers, networks, volumes | docker-compose down
|
Comments
Post a Comment