Getting Started with Docker Compose

Getting Started with Docker Compose

Docker Compose lets you define and run multi-container applications using a single YAML configuration file.

Verify Docker Compose is Installed

docker compose version

Example: Running a WordPress Site

Create a file named docker-compose.yml:

services:
  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wpuser
      MYSQL_PASSWORD: wppassword
    volumes:
      - db_data:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    restart: always
    ports:
      - "80:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: wppassword
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wp_data:/var/www/html

volumes:
  db_data:
  wp_data:

Common Compose Commands

docker compose up -d       # Start in background
docker compose down        # Stop and remove containers
docker compose logs -f     # Follow live logs
docker compose ps          # List running services
docker compose restart     # Restart all services
docker compose pull        # Pull latest images
docker compose exec db bash  # Open shell in a container
  • 0 Корисниците го најдоа ова како корисно
Дали Ви помогна овој одговор?

Понудени резултати

Installing Docker

Installing Docker on Your Dedicated Server Docker allows you to run applications in isolated...

Managing Docker Containers

Managing Docker Containers A practical reference for day-to-day Docker container management. Run...

Using Docker Volumes for Persistent Storage

Using Docker Volumes for Persistent Storage By default, data inside a container is lost when the...

Docker Networking Explained

Docker Networking Explained Understanding Docker networking lets you connect containers together,...

Building Custom Docker Images with a Dockerfile

Building Custom Docker Images A Dockerfile defines the steps to build a custom Docker image for...