Yes, it's Haru Usagi. This time I got a WordPress project at work and I got stuck, so I will write a memo. I think that people who usually touch WordPress know this.
I will look at them in order. First directory structure
wp-template
├── docker-compose.yml
├── wp-config.php
└── wp-content
    ├── index.php
    ├── languages
    ├── plugins
    ├── themes
    ├── upgrade
    └── uploads
At worst, it works if you have the docker-compose.yml and wp-content folders.
If you do docker-compose up, the contents of wp-content will be automatically configured as the initial ones.
wp-config.php is a required file for WordPress. Will it be automatically generated during installation? It looks like, but in my case it didn't do it, so official wp-config.php I changed it for reference.
docker-compose.yml
version: "3"
services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress #Any
      MYSQL_DATABASE: wordpress #Any
      MYSQL_USER: wordpress #Any
      MYSQL_PASSWORD: wordpress #Any
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306 
      WORDPRESS_DB_USER: wordpress #Any
      WORDPRESS_DB_PASSWORD: wordpress #Any
    volumes:
      - ./wp-content:/var/www/html/wp-content
      - ./wp-config.php:/var/www/html/wp-config.php
volumes:
  db_data:
I thought it would be easier to manage DB-related items in .env. Now when you access [http: // localhost: 8000 /](http: // localhost: 8000 /), you will see the familiar WordPress screen.
What you can do normally up to this point.
I can't upload an image to post in WordPress!
When I looked it up, it seems that I have to add a sentence in wp-config.php.
wp-config.php
define('DB_NAME', 'wordpress'); #docker-compose.What was set in yml
define('DB_USER', 'wordpress'); #docker-compose.What was set in yml
define('DB_PASSWORD', 'wordpress'); #docker-compose.What was set in yml
define('DB_HOST', 'db'); #docker-compose.mysql container name defined in yml
define('WP_DEBUG', true);
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');
define('UPLOADS', 'wp-content/uploads' ); #Add this
$table_prefix = 'wp_';
if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
This is the final form of code. The code that needed to be added below.
define('UPLOADS', 'wp-content/uploads' );
sed: cannot rename ./xxxxx Device or resource busy is displayed and the container does not start.
When I looked it up, the following article came out. This is the solution. The wisdom of our ancestors is wonderful.
https://qiita.com/suzukihi724/items/e56fa9516639c6c90a33
I've been using WordPress since I was a student, but it wasn't difficult because it was a MAMP environment. This time I built the environment with docker, so I thought that I could understand the deep part of WordPress. I think that it was normal content for those who usually touch it. .. ..
Recommended Posts