Advertisement
gadgeteerza

Wordpress stack composer file for shared database

Oct 22nd, 2022 (edited)
1,287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.63 KB | Source Code | 0 0
  1. version: "2.1"
  2. # Creates WordPress container and links to db container via user-defined network mysql-net
  3. # Video at https://www.youtube.com/watch?v=NdwB5TPXCnQ explains the file
  4. services:
  5.   wordpress:
  6.     image: wordpress:latest
  7.     container_name: wordpress
  8.     hostname: wordpress
  9.     restart: always
  10.     # Connect to the database container's network
  11.     networks:
  12.      - mysql-net
  13.     ports:
  14.      # Exposes an external port 8080 to an internal container port 80
  15.       - 8080:80
  16.     environment:
  17.      # This variable points this container to the container called db for database
  18.       WORDPRESS_DB_HOST: db
  19.       # Root user so we don't have to add a new user for each service to database
  20.       # (but you can name one with own password, just don't forget to create user in database before running the container)
  21.       WORDPRESS_DB_USER: root
  22.       # Database user's password (if not root user, then set for user)
  23.       WORDPRESS_DB_PASSWORD: dbrootpassword
  24.       # Just make sure you create an empty database in MariaDB with this name first before spinning up this stack
  25.       WORDPRESS_DB_NAME: wordpress
  26.     volumes:
  27.      # Sets a persistent volume called wordpress which maps inside the container as /var/www/html
  28.       - wordpress:/var/www/html
  29.  
  30. volumes:
  31.  # Create volume called wordpress for persistent storage
  32.   wordpress:
  33.    # Specify name so it does not append stack name and become wordpress_wordpress
  34.     name: wordpress
  35. networks:
  36.   mysql-net:
  37.    # Joins existing network of this name (it was created by db container)
  38.     external: true
  39.     # Specify name so that it does not append stack name
  40.     name: mysql-net
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement