I’m going to post a partial answer to start the discussion in the hope of getting some helpful comments to fill in the blanks or alternative answers…
Step 1: Install and Set Up boot2docker
Docker only runs on Linux. So in order to use Docker on our Mac, we need to install boot2docker
, which will run Docker in a Linux VM. You can install boot2docker
using Homebrew:
brew install boot2docker
Once it has finished installing, set up and start boot2docker:
boot2docker init
boot2docker start
Next, we need to run a command to set up some environment variables so that docker-compose will know to find Docker inside our boot2docker VM.
eval "$(boot2docker shellinit)"
You may want to add the lines that export variables to your ~/.bash_profile
so that you don’t have to run the command every time you open a new terminal window.
Step 2: Install docker-compose
There is a Docker plugin called docker-compose
(originally called fig
) which makes it really easy to define the relationship between your Docker containers. You can also install it using Homebrew:
brew install docker-compose
Step 3: Create docker-compose.yml
There’s an official WordPress Docker image in the Docker registry. It includes some information about manually starting up Docker with all of the command line flags necessary to make it all work. As far as I can tell, you can skip all of that because we will be using docker-compose
. In the directory where you will be working on your WordPress theme, create a docker-compose.yml
with the following contents:
wordpress:
image: wordpress
links:
- db:mysql
ports:
- 8080:80
volumes:
- .:/var/www/html/wp-content/themes/my-theme-name
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: example
The volumes
configuration links our theme files in our current directory to a new theme directory inside the Docker container.
Step 4: Start the containers
Run docker-compose up
and you will set up two Docker containers (“wordpress” and “db”) running an installation of WordPress.
Step 5: Open the site in the browser
Our docker-compose.yml
configuration specified that we are forwarding port 80 to port 8080. Also, boot2docker
runs its VM on a specific IP address. Thus, in order to figure out the URL, we need to use the boot2docker ip
command:
open http://$(boot2docker ip):8080
Questions
Now that I have the containers up and running, I have a few questions…
-
Is there an automated way of setting up the boot2docker environment variables, other than copy and paste the exports listed in
boot2docker shellinit
? -
When I’m working on a Rails application, I like to use Pow so that I can access the app using a named
.dev
domain instead of working with specific ports/IPs. How can I configure my system (or Pow) so that I can access the host using http://mysite.dev? -
Are there any steps that I missed? Or are there any steps that should be added to the end?