简体   繁体   中英

How to access the Django app running inside the Docker container?

I am currently running my django app inside the docker container by using the below command

docker-compose run app sh -c "python manage.py runserver"

but I am not able to access the app with local host url, (not using any additional db server or ngnix or gunicorn, just simply running the django devlopment server inside the docker).

please let me know how to access the app

docker-compose run is intended to launch a utility container based on a service in your docker-compose.yml as a template. It intentionally does not publish the ports: declared in the Compose file, and you shouldn't need it to run the main service.

docker-compose up should be your go-to call for starting the services. Just docker-compose up on its own will start everything in the docker-compose.yml , concurrently, in the foreground; you can add -d to start the processes in the background, or a specific service name docker-compose up app to only start the app service and its dependencies.

The python command itself should be the main CMD in your image's Dockerfile. You shouldn't need to override it in your docker-compose.yml file or to provide it at the command line.

A typical Compose YAML file might look like:

version: '3.8'
services:
  app:
    build: .       # from the Dockerfile in the current directory
    ports:
      - 5000:5000  # make localhost:5000 forward to port 5000 in the container

While Compose supports many settings, you do not need to provide most of them. Compose provides reasonable defaults for container_name: , hostname: , image: , and networks: ; expose: , entrypoint: , and command: will generally come from your Dockerfile and don't need to be overridden.

Try 0.0.0.0:<PORT_NUMBER> (typically 80 or 8000), If you are still troubling to connect the server you should use the Docker Machine IP instead of localhost. Enter the following in terminal and navigate to the provided url:

docker-machine ip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM