Docker Interview Questions & Notes

Docker Interview Questions & Notes 

Now, let's go through some useful Docker commands:

  1. docker build: Build an image from a Dockerfile
  2. docker run: Run a container from an image
  3. docker ps: List running containers
  4. docker images: List available images
  5. docker stop: Stop a running container
  6. docker rm: Remove a container
  7. docker rmi: Remove an image
  8. docker exec: Execute a command in a running container
  9. docker logs: View logs of a container
  10. docker-compose up: Start services defined in a docker-compose.yml file

Auto-scaling with Docker Swarm:

Docker Swarm is Docker's native clustering and orchestration solution. Here's a basic example of how to use it:

  1. Initialize a Swarm:
    docker swarm init
  2. Create a service with multiple replicas:
    docker service create --name my-web-app --replicas 3 -p 80:3000 my-nodejs-app
  3. Scale the service:
    docker service scale my-web-app=5

This will increase the number of replicas to 5.

Understanding Docker Compose:

Docker Compose is a tool for defining and running multi-container Docker applications. Here's a simple docker-compose.yml file for our Node.js app:

yaml
version: '3' services: web: build: . ports: - "3000:3000" redis: image: "redis:alpine"

To run this composition:

docker-compose up

This will start both the Node.js app and a Redis container.

To stop and remove the containers:

docker-compose down

Post a Comment

Previous Post Next Post