0

I am playing around with Docker Desktop for Windows (just starting out) and have this simple docker-compose.yml which works great:

version: '2.1'

services:
   db:
     image: mysql:latest
     container_name: wordpresslab_db
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_USER: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_PASSWORD: wordpress

   phpmyadmin:
     image: phpmyadmin/phpmyadmin
     container_name: wordpresslab_phpmyadmin
     volumes:
       - /sessions
     ports:
       - "8090:80"
     depends_on:
       - db

   wordpress:
     image: wordpress:latest
     container_name: wordpresslab_wordpress
     volumes:
       - ./:/var/www/html
     ports:
       - "8080:80"
     depends_on:
       - db
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    db_data:

Once I run docker-compose up -d it creates the containers for database, phpmyadmin and wordpress website and are accessible and working OK.

My question is, how could I setup "project.dev" instead of a "localhost:8080" to access wordpress site and "phpmyadmin.dev" instead of a "localhost:8090" to access phpmyadmin? What other tools do I need? Note that I am using Windows 10 as host.

Community
  • 1
  • 1
Janez
  • 2,336
  • 5
  • 25
  • 37

1 Answers1

1

I think you want to use port mapping as described in the networking doc.

https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-networking#network-creation

There's also a Docker doc on ports in compose files.
https://docs.docker.com/compose/compose-file/#long-syntax

Please note that there are differences in syntax depending on which version of docker compose you are using. You can check your version by running this command in a command prompt: docker-compose --version

Let me know if you're still running into trouble!