$ sudo docker run -p 5000:5000 --rm flaskapp_container * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: 473-505-51
with conu.DockerBackend() as backend: image = backend.ImageClass("flaskapp_container") options = ["-p", "5000:5000"] container = image.run_via_binary(additional_opts=options) try: # Check that the container is running and wait for the flask application to start. assert container.is_running() container.wait_for_port(PORT) # Run a GET request on / port 5000. http_response = container.http_request(path="/", port=PORT) # Check the response status code is 200 assert http_response.ok # Get the response content response_content = http_response.content.decode("utf-8")
# Check that the "Hello Container World!" string is served. assert "Hello Container World!" in response_content
# Get the logs from the container logs = [line for line in container.logs()] # Check the the Flask application saw the GET request. assert b'"GET / HTTP/1.1" 200 -' in logs[-1]