How to expose graphql oasgraph in Docker image?
See original GitHub issueI am creating an application in loopback 4, using graphql.
The problem I have is that I can not expose graphql oasgraph in Docker image
I have two options: 1 - Create a new dockerfile to expose graphql. 2 - Use the same loopback dockerfile to expose port 3000 (Explorer API at http://127.0.0.1:3000/explorer), and 3001 for graphql (http://127.0.0.1:3001/graphql).
How can I configure my dockerfile, in order to expose the graphql server?
https://loopback.io/doc/en/lb4/exposing-graphql-apis.html
This is my dockerfile
FIRST OPTION
# Check out https://hub.docker.com/_/node to select a new base image
FROM hasura/graphql-engine
# Create app directory (with user `node`)
RUN mkdir -p /home/node/app
WORKDIR /home/node/app
RUN npm i -g openapi-to-graphql-cli
RUN npx oasgraph http://localhost:3000/openapi.json/
# Bind to all network interfaces so that it can be mapped to the host OS
ENV HOST=0.0.0.0 PORT=3001
EXPOSE ${PORT}
CMD [ "npx", "oasgraph", "http://localhost:3000/openapi.json/" ]
SECOND OPTION:
# Check out https://hub.docker.com/_/node to select a new base image
##FROM node:10-slim
## node con oracle instant client
FROM collinestes/docker-node-oracle
# Set to a non-root built-in user `node`
USER node
# Create app directory (with user `node`)
RUN mkdir -p /home/node/app
WORKDIR /home/node/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY --chown=node package*.json ./
RUN npm install
# Install openapi-to-graphql-cli
RUN npm i openapi-to-graphql-cli
# Bundle app source code
COPY --chown=node . .
RUN npm run build
# RUN oasgraph
RUN npx oasgraph http://localhost:3000/openapi.json/
# Bind to all network interfaces so that it can be mapped to the host OS
ENV HOST=0.0.0.0 PORT=3000
EXPOSE ${PORT}
CMD [ "node", "." ]
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
A better way to develop your GraphQL API using Docker + ...
A the end of this tutorial, you will have a GraphQL API exposing data from a PostgreSQL database, both running locally on your...
Read more >Containerizing the Apollo Router - Apollo GraphQL Docs
Here's a basic example of running a router image with Docker (make sure to replace <image version> with whichever version you want to...
Read more >How to Deploy a GraphQL API in a Contained Environment ...
You create a YAML file to configure a set of services, based either on existing images (from public sources such as Docker Hub...
Read more >Generating GraphQL-Wrappers for REST(-like) APIs
OASGraph takes as input an OpenAPI Specification (OAS) describing an existing REST(-like) web API and generates a GraphQL wrapper for it.
Read more >Announcing LoopBack 4 GA is Now Ready for Production Use!
You can use this tool to expose GraphQL endpoints from your application's REST ... Introducing an Inversion of Control (IoC) container and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Cross posting from: https://github.com/strongloop/loopback-next/issues/3346#issuecomment-515555994
@fga8, I might have a working Dockerfile for you:
I’ve indicated 3 places that you need to make changes if you’re using the
Dockerfile
generated by the LoopBack cli. Please note that I’m not a docker expert, so what I have above is something that works, you might be able to find a better solution.For the sake of posterity, let me mention a few challenges:
oasgraph
has been deprecated and the new module isopenapi-to-graphql
openapi-to-graphql
is not using the same port as LB, I’ve used-p
option to specify the port number. (Thanks @ErikWittern)sleep
in theCMD
is needed, otherwiseopenapi-to-graphql
will get started before the openapi is ready from LB.Hope it helps!
Unfortunately, we currently do not have any example Dockerfiles. With the changes that Erik suggested, were you able to make any improvements?