首页 > 解决方案 > Docker container is running but cant find the url

问题描述

My name is Omar. I have a docker container that is currently running. Now I want to go online and see if the docker container is actually running without any issue. I am running the following lines of code and when i run the container, it gives a long pause without anything popping up in my linux terminal. How can I go on my web browser and actually see if my container is running:

(MySplit) omars-mbp:mysplit omarjandali$ docker build -t test_4 .
Sending build context to Docker daemon  56.04MB
Step 1/6 : FROM python:3
 ---> 79e1dc9af1c1
Step 2/6 : WORKDIR tab/
 ---> Using cache
 ---> 4d9f321d66ee
Step 3/6 : COPY requirements.txt ./
 ---> Using cache
 ---> 4def3e385cef
Step 4/6 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> a486e74d993d
Step 5/6 : COPY . .
 ---> 9a8336fb3f2e
Step 6/6 : CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
 ---> Running in baa2d48f3714
Removing intermediate container baa2d48f3714
 ---> 49bf417aeb90
Successfully built 49bf417aeb90
Successfully tagged test_4:latest

Then i ran the following code:

(MySplit) omars-mbp:mysplit omarjandali$ docker run -d -p8000:80 test_4
af875ce118423a8b35b7843127b572c47427a0891a8a0a768a1625367ec315aa
(MySplit) omars-mbp:mysplit omarjandali$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                          PORTS                  NAMES
af875ce11842        test_4              "python manage.py ru…"   8 seconds ago       Up 11 seconds                   0.0.0.0:8000->80/tcp   frosty_carson

How can i access the running container on my web browser to see if it is working properly before pushing it to dockerhub

标签: pythondockerdockerfile

解决方案


in your build logs below:-

Step 6/6 : CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

you are running the server on port 8000

so to run the things perfectly you need to do things like below for running the container using our image:-

docker run -d -p <port>:8000 test_4

here <port> will be dynamic, you can choose it yourself, as per your needs and after that, it should be available at http://localhost:<port>


推荐阅读