How to run multiple separate Wordpress sites using Docker containers

I am very new to Docker and I am currently trying to get a Wordpress website up and running (only on my local machine for testing, not actually hosting). I currently have three containers: one Linux distribution for storing my data, used by the MySQL container, and finally the Wordpress container.

I can successfully access and edit my Wordpress website, but I would like to try to run multiple websites on different ports and have no idea how. Should I create three new containers, or can I use the same MySQL containers and datastores and just create a different Wordpress container?

Any help would be appreciated, thanks!

+3


source to share


2 answers


If you are using the official Wordpress image, you can use the same MySQL container. Just specify a different database for each Wordpress container. You can define a database for a Wordpress container with environment variables like:

docker run --name wordpress1 --link some-mysql:mysql -p 8080:80 -e WORDPRESS_DB_NAME=wordpress1 -d wordpress



docker run --name wordpress2 --link some-mysql:mysql -p 8081:80 -e WORDPRESS_DB_NAME=wordpress2 -d wordpress

docker run --name wordpress3 --link some-mysql:mysql -p 8082:80 -e WORDPRESS_DB_NAME=wordpress3 -d wordpress

+6


source


As long as they use the same db or the same db server (which by the way does not put your database into a container, the database writes to disk and defeats the purpose of using the container, unless that container ever don't change location), your best bet is to create new wordpress containers for each one, they can share container layers, so 3 wordpress containers won't be too big, the only layer will be the site code, so your best bet.



0


source







All Articles