Running wordpress in docker container

For long time I wanted to have backup of lemilica, as I had lots of problems with site remaining up.

So few days ago I decided to try docker containers.

Create wordpress.yml with your favorite editor

mkdir wordpress_docker
cd wordpress_docker
nano wordpress.yml

Copy code bellow to the file. If you do not need phpadmin you can remove those lines


version: '3.3'

services:
  mysql:
    image: mysql:5.7
    restart: always
    volumes:
      - mysql-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: your_MYSQL_ROOT_PASSWORD
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: your_WORDPRESS_DB_PASSWORD

  wordpress:
    depends_on:
      - mysql
    image: wordpress:latest
    restart: always
    ports:
      - 8081:80
    volumes:
      - .wordpress/plugins:/server_wordpress_path/plugins
      - .wordpress/themes:/server_wordpress_path/themes
      - .wordpress/uploads:/server_wordpress_path/uploads
    environment:
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: your_WORDPRESS_DB_PASSWORD
      WORDPRESS_DB_NAME: wordpress
   
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    environment:
      PMA_HOST: mysql
    ports:
      - 8082:80

volumes:
  mysql-data: {}

Change your_MYSQL_ROOT_PASSWORD and your_WORDPRESS_DB_PASSWORD to something else,change server_wordpress_path to some path on server wordpress can access and run with

docker-compose -f wordpress.yml up -d

That should give you wordpress running on port 8081 and phpadmin on port 8082

Leave a Reply