I’m new to Docker. Currently I have a working WordPress container in localhost:8000, but I’m trying to create a virtual host for it, so I will be able to access it by http://starter.dev, and nothing works. I have edited my docker-compose.yml file according to the docs, but still no luck. Nothing is added to hosts file, and if I manually add it, I cannot reach the site at all.
This is how my docker-compose.yml file looks like:
Your extra_hosts setting actualy works, exec into the container and curl the domain… you will see that it works. But this setting will have no effect on your host.
Thus said, I am pretty sure this is not what you want… You want the domain starter.dev to be resolvable from your host, don’t you?
If so, you will either need to edit the c:\Windows\System32\drivers\etc\hosts file (which is the windows equivalent to Linux /etc/hosts) OR preferably add a dns server to your network that manges the name resolution for you in a proper way.
In home lab environment I tend to use pihole for that, even though its primary functionality is to filter domains based on lists, one of the secondary functions is to manage arbitrary domains and register A, AAAA or CNAME records for those within your network. Pihole makes it realy easy to do that.
You should consider to solve the missing name resolution on the level it emerges: on the dns level.
You did edit the windows host file and add those entries, right?
What happens if you ping those domains in windows?
I am sure a short google search will yield dozens of blog posts that tall you how it’s done, BUT: once setup, you will need to loop it into your network configuration. Either on the host, OR configure as the dns server your dhcp server announces OR as primary dns server for wan connection. As this will affect your network name resolution, I strongly recommend to NOT run Pihole on a desktop computer. If you run a docker capable NAS, a pihole, or another 24/7 running server → run it there.
If you feel overwhelmed by the idea of running your own pihole, then probably the solution is unsuited for you, and you might stick to manipulating the hosts file.
Never the less, docker is not responsible for your network name resolution by itself. You could choose to run phole in docker, or directly on your host, or on a raspberry pi, but that would be custom solution introduced by yourself, and nothing that docker is responsible of.
This indicates that it’s working. So nameresolution is not your problem (anymore).
According the details you shared and the published port for the wordpress service, this URL should work in the browser: http://www.starter.dev:8000
If not, check the logs of the containers,