Pattee Green
Jul 30, 2017 · 3 min read

I’m new to Docker and I’ve been trying to improve my skills. I’ve been taking this awesome course on Udemy to expand my skill set. If you need some Docker improvement I’d highly recommend it. I’ve also been making WordPress sites for a while now, but always used WAMP to host the sites on my local environment while I’m developing. I recently chose to do a refresh on my computer and needed to re-install WAMP.

I started to re-install WAMP, but since I had Docker knowledge on the brain using Docker instead of re-installing WAMP was the perfect solution. Now I can use Docker to set up my environment instead of having to maintain WAMP on my computer. I used the docker-compose file that supplied by the course I mentioned above. But I was getting errors that indicated my Apache file needed to be configured. I wasn’t sure how to go about doing that. So after researching and figuring it out I wanted to leave instructions for future me- and others. In case I need to do this again.

So I am using Docker to run WordPress with a docker-compose.yml file. My docker compose file starts two containers. A WordPress container and a MariaDB container. To reach the Apache configuration file you’ll need to start an interactive session with the WordPress container. the WordPress container runs the Apache server and has PHP installed.

So these instructions are useful for my particular situation, but anyone that needs to adjust their config file in Apache while using Docker could also find some useful info here.

Here’s the error:
MySQL connection Error: (2002) Connection refused.
apache2: Could not reliably determine the server’s fully qualified domain name, using 172.18.0.3. Set the ‘ServerName’ directive globally to suppress this message.

My research told me to add ‘ServerName localhost’ as the last line in the file apache2.config.

In the docker command line, start with running the docker-compose command in detached mode. This will run things in the background. And you’ll still have access to your command line. To do that, when you docker-compose up use the -d flag.
docker-compose up -d

Run an interactive session into the WordPress container using:
docker exec -it wordpress_container_id /bin/bash

Now the commands I list are going to be in the interactive session.

I found my apache configuration file at: ./etc/apache2/apache2.conf. But if you need/want to search the files in the container you can. First, get into the root by typing:
cd /

Then run a search command to find apache config:
find . -name ‘apache2.conf’

Docker doesn’t come with any text editor, Vim is my choice on text editor to install. To install Vim run:
apt-get update
apt-get install vim

If you want a cheat sheet for Vim: https://vim.rtorr.com/. Otherwise I’ll give you the couple of commands needed below.

Open the apache file with Vim:
vim ./etc/apache2/apache2.conf

In Vim:
Type i for interactive mode that allows you to type.
Press down arrow key to get to bottom of file.
Add the line ‘ServerName localhost’. (no quotes)
Press escape key to get out of interactive mode.
Type :wq to save and quit.

Restart Apache:
/etc/init.d/apache2 restart

That kicked me out of interactive mode and stopped my container. I ran docker-compose up again. And everything worked for me. Feel free to leave questions or let me know if my directions don’t work for you. Also, since I am new to Docker if you see errors or omission feel free to comment.