It’s not easy to understand what Docker is and how to install WordPress with Docker. But we’re so grateful for the many guides on the great web. Docker has a variety of features that helps make using WordPress even easier than ever – and we’re excited so share how you can have your part with Docker.
What is a Docker?
With master abilities to change a developer’s life, Docker is a multi-platform possessing the ability to build and destroy an application faster than any virtual machine. (We call Docker the useful little app that makes managing different versions of applications and other software easy.)
This open platform is used for developing, shipping, and running applications. The methodologies of Docker enable you to ship and develop code immediately – significantly reducing the delay between manually writing code and running it.
With Docker, the users will face no difficulty setting up their work environment. Moreover, once you’ve installed Docker, you won’t need to install dependencies manually again. If you’re an entrepreneur with some workers or a solo-preneur running the agency on their own, all you’ll need is to share your configuration code with the other worker, and boom – you’re set to work.
[Related Article: Compose WordPress with Docker]
Installing WordPress with Docker
Now that you understand what Docker is and how it works, let’s discuss how you can install it. If you have Docker-compose.yml and Docker-Compose on your computer/server, the next steps are here.
1) Start Docker:
Once installed, you can use it to install an app, set up a virtual machine sandbox, or run any other command as if it were native to your Mac. Docker uses containers to keep multiple applications in separate but easily accessible sandboxes. It has a simple icon on the menu bar and gives you convenient access to your apps.
2) Make New Directory:
In this section, we’ll create a directory to build our WordPress theme. If you like, create a new folder wherever you want and name it whatever you want. We’ll set up our entire WordPress ecosystem in this directory.
3) Docker-compose.yml
For the remainder of this tutorial, you will need some familiarity with Terminal and a code editor of your choice. I’ll still call out specifically Terminal commands so that no one gets lost along the way.
Now it’s time to create and run your Docker compose file. Create a blank file named docker-compose.yml in your code editor and save it in the directory you created in
Section 3. This is the file Docker will use to set up WordPress and the MySQL database.
Open the Terminal by clicking the Launchpad icon, then click the Other Folder at the top of the screen. Then click Utilities and finally click Terminal. When you start Terminal, the blank screen will likely be in your home directory. Just in case, type the command below and hit ‘return’:The CD command means “change directory,” The tilde is a shortcut to the home directory. So we now have navigated to our home directory. Next, we need to navigate the directory created by make_directory in Section 3. For me, I type:
cd docker-WordPress-theme-setup
You should see your docker-compose.yml file when you open up Docker Compose. It should look like this: Now, we can add some instructions to create our WordPress setup. Add the following to docker-compose.yml and save it in your code editor.
uploads.ini
Because we’re working locally and not on a real server (yet), we need to make sure the server knows how to handle uploaded files. So, we need to create one more file before running the installation command. In the docker-compose.yml file at the end, directly below where we define the wp-content directory, you’ll see a second parameter defining a uploads.ini file. Please create a new file and save it as uploads.ini in the same directory the docker-compose.yml file is in. paste the following into the file
file_uploads = On
memory_limit = 64
Mupload_max_filesize = 64M
post_max_size = 64
Mmax_execution_time = 600
The default upload limit for Docker is 2 MB, but it’s not ideal for local development environments. To increase the upload limit, we create our file uploads.ini, setting a new and generous limit there. It’s important to create this file first because if you run the docker command in Section 6 before the file exists, it will create it as a directory, and your configuration won’t take effect because it’s a folder (not a file). There’s likely a better setup to avoid this, but this gets the job done for now.
4) Run Docker Compose:
Now that we have the required Dockerfile and docker-compose.yml, we are ready to run the Docker command to build our local environment. In Terminal, make sure you are still in the directory we created in Section 3 (again, you can check for the docker-compose.yml file by typing the ls command) and run the following command (when Iwesay “run,” it means type and hit enter, just in case that’s not obvious.
docker-compose up –d
Downloading and installing system updates is something you can do very quickly. The Terminal will begin running scripts, and you should see various “Downloading” and “Waiting” messages appear in the Terminal. This will take a little while to run.
Related Article: How to run Docker compose
Install WordPress:
When the script is done running, go to this URL in your browser (or if you changed the port number, go to whatever port you changed it to):
http://localhost:8000/
Congratulations! You have successfully installed WordPress on your site. Let’s make sure WordPress knows who you are to recognize you and your site in the future. Log into WordPress and visit the ‘Users’ section of your dashboard. Then select ‘Your Profile’ to update your user information with your details.
Restarting:
If Docker is not running, you can access the WordPress install at http://localhost:8000/. If Docker isn’t working to access the site, restarting it usually fixes the problem. To restart Docker, click on its icon in the upper right corner and select “Restart” from the dropdown menu that appears.
In Summary:
While installing WordPress with Docker could sound challenging, or too technical, it’s all very simple. However, when it comes to making WordPress changes, you could always feel free to reach out to professional WordPress website developers. This might be your best option, as we can download/install and manage any updates to your WordPress site, with or without Docker.