We will use a tool called Docker Compose that enables running multi-container docker applications. You will use a YAML file to configure your application's services.
Using compose consists of 3 steps:
The first definition in the yaml file below is for the web service.
build: build it from the Dockerfile in the parent directory
links: link to the database container
ports: map the external port 8000 to the internal port 80
volumes: map the parent directory on the host to /app in the container, with read and write access. map the data directory on the host to /data in the container, with read and write access
command: by default, when the command docker-compose run is issued, execute python manage.py runserver 0.0.0.0:80
env_file: use the .env-local to supply environment variables to the container
# docker-compose.yml
web:
build: .
links:
- "db:postgres"
ports:
- "8000:80"
volumes:
- ".:/app:rw"
- "./data:/data:rw"
command: python manage.py runserver 0.0.0.0:80
env_file: .env-local
db:
image: postgres:9.4
volumes:
- ".:/app:rw"
docker-compose start
docker-compose stop
docker-compose pause
docker-compose unpause
docker-compose ps
docker-compose up
docker-compose down
mkdir wordpress && cd wordpress
You can use the command line interface or any text editor to create the file. Make sure that it is stored in the root directory. The docker-compose.yml file can also be obtained from the docker documentation for wordpress https://docs.docker.com/compose/wordpress/
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wordpress_data:/var/www/html
ports:
- "8001:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}
docker-compose up -d
# runs docker-compose up in detached mode,
# pulls the needed Docker images,
# and starts the wordpress and database containers
You can now proceed with the Wordpress installation.
Right Click on the Docker icon in the Windows Task bar Click Settings >> Resources >> File Sharing >> Click the + button and add the directory where your docker project is.
https://docs.docker.com/compose/
https://gist.github.com/jonlabelle/bd667a97666ecda7bbc4f1cc9446d43a
https://docs.divio.com/en/latest/reference/docker-docker-compose/