version: '3' -> docker compose version (required)
services: (required)
wordpress:
image: wordpress: 5.6-php7.4 -> image name
environment: -> default variables on docker hub: https://hub.docker.com/_/wordpress
WORDPRESS_DB_HOST: db -> "db", docker compose will auto networking services
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: 123456
WORDPRESS_DB_NAME: wordpress
volumes:
- wordpress: /var/www/html
ports: -> set a port
- 8080: 80
depends_on: -> "db" should be create first
- db
restart: always
db:
image: mysql:5.7 -> image name
environment: -> default variables on docker hub: https://hub.docker.com/_/mysql
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: 123456
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- wordpress: /var/lib/mysql
restart: always
volumes: -> data on container will be delete you delete container, so use "volumes" to save data (optional)
wordpress:
db:
docker-compose up
docker-compose up -d
-> detach mode, docker will run on backgrounddocker container ps
docker-compose ps
docker-compose stop
docker-compose config
-> check yaml filedocker-compose config -q
-> check yaml file quiet modedocker-compose start
-> restart containerdocker volume ls
-> check dirdocker inspect volume VOLUME_NAME
-> check detailsudo ls -la VOLUME_DIR
-> check dir folderdocker-compose top
-> check processingdocker-compose top CONTAINER_NAME
-> check processing detaildocker-compose logs
-> check logsdocker container exec -it CONTAINER_ID /bin/bash
-> access containerdocker-compose rm
-> delete
ipconfig