Local WordPress Development Environment with Docker

Local WordPress Development Environment with Docker


Run MySQL container
docker run --name wordpressdb -d mysql:5.7
docker run --name wordpressdb -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7

The one to use
docker run --name wordpressdb -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=wordpress -d mysql:5.7


Run WordPress Container (which based on an apache Dockerfile with php enabled)

docker run -e WORDPRESS_DB_PASSWORD=password -d --name wordpress --link wordpressdb:mysql -p 80:80 -v "$PWD/":/var/www/html  wordpress

Customised Dockerfile

Download the Official Dockerfile

Wordpress Dcokerfile

Add PHP-ZipArchive Extension

RUN set -ex; \
	savedAptMark="$(apt-mark showmanual)"; \
	apt-get update; \
	apt-get install -y --no-install-recommends \
		libjpeg-dev \
		libpng-dev \
	; \
	docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
	**docker-php-ext-install gd mysqli opcache;** \

Edit docker-php-ext-install gd mysqli opcache; \
To docker-php-ext-install gd mysqli opcache php-zip; \


Add the below code block

# add zip extension
RUN apt-get update \
    && apt-get install -y zlib1g-dev \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install zip 

Build docker image

docker image build ./ -t cuswordpress


-e: env variable
--link: add link to container
-d: detach
-p: Port mapping
-v: Volume mapping
$PWD: Present Work Directory