Reputation: 15466
I am creating an Nginx container that I would like to access locally at http://api
. Using Docker Machine, I assumed running docker-machine create default
and docker-machine ip default
to receive the IP and editing my hosts file to something like this:
# docker-machine ip default --> 192.168.99.100
192.168.99.100 api
should map requests to api\
to the Docker Machine IP and serve my content.
Two things are confusing me:
http://localhost
. However, running docker-machine ls
returns no machines. This is confusing because I thought Docker had to run on a VM.http://localhost
but not http://api
Instead of accessing my container at http://localhost
I want to access it at http://api
. How do I do this?
I'm using Docker for Mac 17.12 and Docker Machine 0.14.
Upvotes: 1
Views: 1805
Reputation: 59896
On the base of your this question:
Instead of accessing my container at http://localhost I want to access it at http://api. How do I do this?
Your docker run command:
docker run -it --rm --name test --add-host api:192.168.43.8 -p 80:80 apachehttpd
1st Thing: The --add-host
flag add value to /etc/hosts in your container /etc/hosts
so http://api will also response inside the container if ping inside that container.
This is how will ping response inside container
2nd Thing: Edit your host etc/hosts
file and add
api 192.168.43.8 [your ip]
This is how you can see in Browser.
Upvotes: 2