In the past few days, I was just trying to get myself use to using Docker under Linux and I found it very useful not just getting everything working as it should but to understand how Docker works with Linux.
While using Docker, I have learned that since Docker is running natively without any kind of virtualization because its installed natively, so technically you can setup static IP in other words, using the Docker’s IP address of 172.26.x.x, so you can actually use these IPs and setup inside of your hosts file, this way, you can actually setup WordPress on different IPs and use some kind of hostname along with it.
Here is what my setup looks like.
version: '2' services: sandbox: image: wordpress:php7.1-apache container_name: sandbox_wordpress ports: - '80' environment: WORDPRESS_DB_NAME: sandbox WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: sup1er2man3 WORDPRESS_TABLE_PREFIX: wp_sandbox_ volumes: - './public_html:/var/www/html' networks: mynet: ipv4_address: 172.26.0.5 themereview: image: wordpress:php7.1-apache container_name: themereview_wordpress ports: - '80' environment: WORDPRESS_DB_NAME: themereview WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: sup1er2man3 WORDPRESS_TABLE_PREFIX: wp_themereview_ volumes: - './public_html:/var/www/html' networks: mynet: ipv4_address: 172.26.0.6 mysql: image: mariadb container_name: sandbox_mysql environment: MYSQL_ROOT_PASSWORD: example MYSQL_DATABASE: sandbox MYSQL_USER: wordpress MYSQL_PASSWORD: sup1er2man3 volumes: # - db_data:/var/lib/mysql - './docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d' networks: mynet: ipv4_address: 172.26.0.7 aliases: - mysql phpmyadmin: image: phpmyadmin/phpmyadmin container_name: sandbox_phpmyadmin environment: - PMA_ARBITRARY=1 ports: - '80' volumes: - /sessions networks: mynet: ipv4_address: 172.26.0.8 #volumes: # db_data: networks: mynet: driver: bridge ipam: config: - subnet: 172.26.0.0/24
In the database section, i have created a new file called init.sh inside of the docker-entrypoint-initdb.d folder so I can create multiple database since the docker only allows one for now.