Look, I know there’s a lot of Docker and WordPress stuff on the Web but I just wanted to make a little cheatsheet for me and my boys to rapidly dockerize WordPress websites and deploy it to production. I believe you can use it too. It also highlights a lot of my favorite tools that you might like. Ok, let’s get to the business.
- Create VPS server. I prefer Ubuntu 16.04 on Hetzner Cloud for their nice UI, good uptime and very low prices. Also it wasn’t ever been blocked in Russia.
- Install Docker. Feel free to use my little snippet like that:
curl https://gist.githubusercontent.com/michaelradionov/84879dc686e7f9e43bc38ecbbd879af4/raw/17f942d078b5b2202dd12eab9a5c4d55b4a06259/Docker_Ubuntu_16.sh | sudo bash
3. Then I suggest you to install my BDSM script. Pretty cool naming isn’t it? :) It’s my swiss knife for a various WordPress, Laravel, MySQL and other purposes.
eval "$(curl "https://raw.githubusercontent.com/michaelradionov/gg_installer/master/gg_installer.sh")" && gg_installer bdsm;
4. Then you might want to set you terminal prompt the way you like with HelloBash Bash prompt configurator . It should be installed with BDSM automatically. You just run
helloBash and follow instructions. Enjoy!
Steps 5–7 are supposed to be executed on your PROD server.
5. Create folder somewhere
7. Clone your WordPress website from remote git repo
git clone <your-website-repo> .
Please admin that you might find more convenient to do actions 8–12 on your local machine then sync your files with Git.
8. Then move up
9. And clone Laraflag repo
git clone https://github.com/michaelradionov/laraflag.git
10. Come back and copy 3 items from laraflag folder to your project
cp -r ../laraflag/docker .
cp ../laraflag/docker-compose.yml .
cp ../laraflag/.env.example .
11. Edit .env.example and commit to your repo
12. Please notice that you have 2 Caddy files in docker/caddy/caddy/conf folder. Caddy will use the value from APP_ENV to determine which file to use. Edit your docker/caddy/caddy/conf/Caddyfile_production file.
Replace all the domain.ru occurrences with your actual domain name. Also you should replace /var/www/public string with /var/www for WordPress site.
13. On the server make your local .env file by running
cp .env.example .env and fill the DB_PASSWORD option with some strong value.
14. Build and run your project with Docker Compose. I prefer to use Docker Aliases (which are also should be installed through BDSM installer) and you can just run
dc up -d caddy mysql. Then you will wait for a couple of minutes. Go make yourself a coffee. ☕
15️. Check if Docker containers are running by executing
dc ps command. You should see something like this:
If it’s not hit me here in comments.
16. Then copy your database credentials from .env to your wp-config.php . I strongly suggest you not to commit wp-config.php . Better use wp-config-sample.php or make your own config template. Don’t forget to replace localhost with mysql value for the DB_HOST variable!
17. If you need a convenient way to deploy your existing database then just use BDSM script for it. You can run it on your local machine, export or pull database from remote server, search/replace domain. And all this you can do with a couple of key strokes. Just run it and check it out!
After that you should be all good with your new Dockerized WordPress website. Feel free to ask me a question. I will answer as soon as I get notification. Enjoy!
To join our community Slack 🗣️ and read our weekly Faun topics 🗞️, click here⬇