I currently have Docker installed on my Windows computer. I have an Ubuntu 18.04 container, which has installed PHP 7.2, Apache2, and MariaDB. The port mapping is as follows:
docker run -it --name my_container -p 8080:80 -p 8081:3306 ubuntu:1804
Previously, before using Docker, I had configured a Virtual Host on my computer for a web project, something like http://my_project.dev to access it instead the typical http://localhost/projects/my_project .
Now that I changed my way of working to Docker, I have my project working perfectly on port 8080, something like this http://localhost:8080/projects/my_project , but I can’t find a way to create a Virtual Host to access my project with http://mi_project.dev in my current Docker container.
hey
if you are having a single container, you can attach the container to host network which will map all the expose port to host port and this way you can access directly via hostname
Your problem is neither a docker problem, nor an apache problem.
Your problem is the missing name resolution for your custom domain.
From what I remember Virtual Hosts are used to add domain specific listeners. They are actualy not responsibil for the name resolution. This is usualy done by dns and can be overriden by entries in the hosts file.
If you already created the entry "127.0.0.1 my_project.dev " in your hosts file (the machine with the browser!), the name resolution part should work.
I must admit it is not clear what you realy want.
What is stopping you from exposing port 80 for your container and configure it in your apache.conf?
I am wondering what makes it impossible for you to apply the knowledge you gained on the host to the container…
The only run command you pasted makes me afraid that you try to use docker in a way it is not designed to be used: as a 1:1 replacement for a vm.
It is impossible to help with the given details. Sorry and good luck on your journey!
You are using Docker now. Virtual host configuration should be inside Docker - not on your local Windows machine.
Create a volume (https://docs.docker.com/storage/volumes/), map a local Apache virtual host file to the one inside the container and set DocumentRoot to eliminate /project/my_project from the URL.
You can then setup Windows’ hosts file and add a domain (my_project.dev) to point to localhost.