GithubHelp home page GithubHelp logo

docker-grpc-cpp's Introduction

A Minimal Docker image with a C++ gRPC server.

This project shows how to create a minimal Docker image containing a C++ gRPC service.

Requirements

Operating System

This demo is intended for Linux systems only. It may work on other operating systems using some form of virtual machine, but I have not tested it.

Docker

You must have Docker installed on your workstation. I have only tested the Docker files with 18.09, but any version greater than 17.05 should work.

Create devtools Docker image

First we create a Docker image with all the development tools necessary to compile the gRPC server. While it is possible to install all these development tools in your workstation, a Docker image makes the remaining steps easier to reproduce.

This step may take a few minutes, as it builds gRPC and other dependencies:

sudo docker build -t grpc-cpp-devtools:latest -f tools/Dockerfile.devtools tools

Create the server Docker image

Once the development tools image is created we can use it to create a Docker image with a C++ gRPC server:

sudo docker build -t grpc-cpp-echo:latest -f examples/echo/Dockerfile.server .

Note that this image is relatively small:

sudo docker image ls grpc-cpp-echo:latest
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
grpc-cpp-echo       latest              04d95e5adaa6        4 minutes ago       14.6MB

Run the server in the Docker image

Use docker run to start a container using this image. You may want to detach from the image using the -d option and capture its id so you can terminate it later:

ID=$(sudo docker run -d -P grpc-cpp-echo:latest /r/echo_server)

Note the mapping of port 7000 to the localhost to ease testing.

Use the client to test connectivity

The image also contains a small client to demonstrate connecting to it:

ADDRESS=$(sudo docker port "${ID}" 7000)
sudo docker run --network=host grpc-cpp-echo:latest /r/echo_client --address "${ADDRESS}"

Terminate the container

sudo docker kill "${ID}"

docker-grpc-cpp's People

Contributors

coryan avatar robshakir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

docker-grpc-cpp's Issues

failed to build the build container because of ninja

when building the dev container under Docker for Windows (by stripping the sudo) ninja fails to install/download

I'm new to linux (haven't been working on it for 15 years) - so here simply the error message

Detecting compiler hash for triplet x64-linux...
A suitable version of ninja was not found (required v1.10.0). Downloading portable ninja v1.10.0...
Downloading ninja...
https://github.com/ninja-build/ninja/releases/download/v1.10.0/ninja-linux.zip -> /l/vcpkg/downloads/ninja-linux-1.10.0.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 624 100 624 0 0 301 0 0:00:02 0:00:02 --:--:-- 301
100 99857 100 99857 0 0 20429 0 0:00:04 0:00:04 --:--:-- 41009
Extracting ninja...
Value was null
The command '/bin/sh -c ./vcpkg install --triplet x64-linux grpc' returned a non-zero code: 1

The "download progress table" was colored in red.

Greetings Sekulian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.