curl Flask web service inside Docker container

I’ve got a Flask web service running in a Docker container on port 5000. How do I curl this service from inside the container? I can curl it from outside, i.e. the host, using curl http://localhost:5000/<path>.

  • List containers in the same docker-compose
  • Localhost connection refused in Docker development environment
  • Can't create docker swarm service
  • Errors while running docker “Error resolving syscall name <>: could not resolve name to syscall - ignoring syscall.”
  • Nginx dockerized accessing host IIS website on a given port
  • How to estimate the VM resources (CPU, RAM, HDD etc) with respect to Docker image size? My images are huge, 5-10 GB
  • Dockerhub Create Automated Build step stuck at Creating
  • Unable to deploy my application to remote docker
  • Problems with database setup on cookiecutter-django
  • File permission error when installing Meteor in Docker
  • How to design Docker routing and database Layer?
  • docker: Fatal Error Unable to create lock file: Bad file descriptor (9)
  • One Solution collect form web for “curl Flask web service inside Docker container”

    Use:

    sudo docker inspect --format='{{json .NetworkSettings.Ports}}' <containername or container id>
    

    In the network section look at ports.

    {
      "443/tcp": [
        {
          "HostIp": "0.0.0.0",
          "HostPort": "8443"
        }
      ],
      "80/tcp": [
        {
          "HostIp": "0.0.0.0",
          "HostPort": "8080"
        }
      ]
    }
    

    As you can see my container is listening on port 80 and 443 so if I use curl inside the container I should use these ports. On the other hand from the docker host I should use HostPorts.

    Alternatively you can look at the Dockerfile to view which ports are exposed.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.