I'm new in docker and I'm struggling with running one image which I would like to access in my localhost. This is the order I'm using.
1.docker-machine start default (starting vm)
2.docker-machine env
3.(coping the @for command which has displayed and paste to my terminal)
4.docker run -d -p 127.0.0.1:8000:80 image_id
it generates the long string, container I guess
5.docker container run image_id - this says that "Application startup complete."
After that, I want to access this in my browser using the above IP. The page cannot be displayed. What am I doing wrong ? I'm a windows user
also this is the terminal message after running the last command:
[2020-04-06 19:50:15 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-04-06 19:50:15 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2020-04-06 19:50:15 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2020-04-06 19:50:15 +0000] [7] [INFO] Booting worker with pid: 7
[2020-04-06 19:50:15 +0000] [7] [INFO] Started server process [7]
[2020-04-06 19:50:15 +0000] [7] [INFO] Waiting for application startup.
[2020-04-06 19:50:15 +0000] [7] [INFO] Application startup complete.
Since you used docker-machine
, look at the output from docker-machine env
to get the IP address of the docker VM. Then connect to that IP address on the published port. Typically that would be port 8000
from your example, however you've bound to the loopback interface which is not externally accessible when you ran:
docker run -d -p 127.0.0.1:8000:80 image_id
So find that container (docker container ls
), stop it (docker container stop
on the container id or name), and start a new one with:
docker run -d -p 8000:80 image_id
Then connect to the docker-machine VM's IP address on port 8000 to access your app. Note that the second port number (80
) in the above command must match the port your application inside the container is listening on. So if you've changed this port in your app based on other answers here, you'll need to change the target port above.