From the course: Web Servers and APIs using C++

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Serving the example

Serving the example - C++ Tutorial

From the course: Web Servers and APIs using C++

Start my 1-month free trial

Serving the example

- [Instructor] Let's run our web server directly in the container. From the build directory, type ./hello_crow. The output looks promising. Our server tells us it is using PORT 18080. Let's try accessing it from the browser. We enter localhost:18080 and press Enter. Uh-oh. We can't access our site. Why? Each docker container is by default isolated. None of its ports are open. In order to access our server, we need to open a port and tell the server which port to use. We open a port by adding the -p option to the docker run command. The -p option opens a port and allows us to map it to the host machine. The first number is the host machine's port number. The second number is the container's port number. The port numbers don't have to match. The -e option allows us to create an environmental variable. We'll use it to tell the server which port it is using. So we go back to the terminal. Control + C to stop that from running. We can exit. Then from here, we're gonna enter docker run -v…

Contents