Skip to the content.

LAMP Example

cd
cd /var/www/html/
mkdir docker
cd docker
docker run -d -p 8888:80 --name $containername -v "$PWD":/var/www/html php:7.0-apache

# or

docker run -d -p 80:80 --name $containername -v "$PWD":/var/www/html php:7.0-apache

To Start

# depends on what you used as a host in docker run command
http://localhost:8888/

# or
http://localhost:80/

To Stop

docker stop $(docker ps -a -q)

What is docker-compose.yml?

Content of docker-compose.yml

version:'3.1'

services:
  php:
    image: php:7.0-apache
    ports:
      - 8888:80
    volumes:
      - ./:/var/www/html

Docker Compose Up

docker compose up -d

Docker Compose Down

To stop running docker images:

docker compose down

Adding MySQL

  db:
    image: mysql:8.0
    # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: "test"
      MYSQL_PASS: "test"
    ports:
      - 3306:3306
  #    volumes:
  #      - $volumename:/var/lib/mysql

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
#volumes:
#  $volumename:

What Happens If docker-compose.yml and Dockerfile Files Are in the Same Directory?

Ref: truthseekers - GitHub