Coder Social home page Coder Social logo

senao_hw's Introduction

User Guide

Setup

$ docker-compose --version
  • If you encounter any permission issues with Docker, please refer to the Post-Installation Step to learn how to manage Docker as a non-root user.

Build and Run API server with docker-compose

  • Write the following code into the docker-compose.yaml file.
version: "3.9"
services:
  postgres:
    image: postgres:14-alpine
    environment:
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=root
      - POSTGRES_DB=senao
    ports:
      - "5432:5432"
    networks: 
      - senao-network
  api:
    image: amboseqiu/senao_hw
    ports:
      - "8080:8080"
    depends_on:
      - postgres
    command: [ "/app/main" ]
    networks: 
      - senao-network
networks:
  senao-network:
    name: senao-network
  • To build the Docker Compose file, make sure you are in the same directory as the file.
$ docker-compose build
  • Run the docker-compose
$ docker-compose up -d
  • The API server will make multiple attempts to connect to the PostgreSQL database in case of failure. Therefore, if you encounter an error message like the one below, there is no need to worry:
root-api-1       | [error] failed to initialize database, got error failed to connect to `host=postgres user=root database=senao`: dial error (dial tcp 172.18.0.2:5432: connect: connection refused)
  • Check docker to ensure that both the API server and PostgreSQL are running. If you see something similar to the following, it means everything is working well.
$ docker ps -a        
CONTAINER ID   IMAGE                COMMAND                  CREATED         STATUS         PORTS                    NAMES
5e53ef45e278   amboseqiu/senao_hw   "/app/main"              7 seconds ago   Up 5 seconds   0.0.0.0:8080->8080/tcp   senao_hw-api-1
b8f1d75b6685   postgres:14-alpine   "docker-entrypoint.sā€¦"   7 seconds ago   Up 6 seconds   0.0.0.0:5432->5432/tcp   senao_hw-postgres-1

senao_hw's People

Contributors

ambroseqiu avatar

Watchers

 avatar

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.