Skip to content

This project shows a simple implementation for an express app with mysql database deployed using docker.

License

Notifications You must be signed in to change notification settings

FawzyMokhtar/Express-App-With-Docker

Repository files navigation

Express App With Docker

This is a simple express app with mysql database deployed with docker.

Table of Content

Prerequisites

You should have all of the following installed before start

Getting Started

  • Database Setup

    1. Follow the instructions to setup a MySQL server on your local machine.

    2. Use workbench or mysql shell to run the following script

      CREATE DATABASE `express-app-with-docker-db`;

      to create an empty to be used in our express app.

    3. Go to the "sequelize.js" file located in the path "src/data/" and make sure all credentials are right.

      Important, any changes in this credentials requires a change to the files "Dockerfile" and "docker-compose.yml" .

  • Start App on Development Environment

    1. Run command

      yarn start
    2. You should see this message

      Express server is up & running on port 8080
  • Deploy to a Docker Container

    • Using Docker Compose

      • If you changed any credentials in the step database setup, you should update these changes in the files "Dockerfile" and "docker-compose.yml" .

      • Also you should update the file "Dockerfile" and use your host machine ip address instead of mine(172.19.0.1).

      • More details are included in the "Dockerfile" and "docker-compose.yml" files.

      • To Build a Docker Image and Deploy to a Docker Container, run command

        docker-compose build
      • To run a docker container for every service in the built docker image (in our case two services web & db), run the command

        docker-compose up -d

        You will get two new containers with the name express-app-with-docker_web_1 and express-app-with-docker_db_1

      • To get the ip address for the newly created express app docker container, run command

        docker inspect express-app-with-docker_web_1 | grep Address

        Now you should have the following message

        "LinkLocalIPv6Address": "",
             "SecondaryIPAddresses": null,
             "SecondaryIPv6Addresses": null,
             "GlobalIPv6Address": "",
             "IPAddress": "",
             "MacAddress": "",
                     "IPAddress": "172.19.0.3",
                     "GlobalIPv6Address": "",
                     "MacAddress": "02:42:ac:13:00:03"

        The value of the "IPAddress": "172.19.0.3" is the ip address for th newly created docker container.

      • To test the app, open your browser on http://172.19.0.3:8080 or http://localhost:8080

        You should get this message

        [
          {
            "id": 1,
            "name": "Samsung Galaxy S5",
            "price": "4500.00"
          },
          {
            "id": 2,
            "name": "Samsung Galaxy S6",
            "price": "5000.00"
          },
          {
            "id": 3,
            "name": "Huawei P10 Lite",
            "price": "5200.00"
          },
          {
            "id": 4,
            "name": "Huawei P30",
            "price": "6500.00"
          },
          {
            "id": 5,
            "name": "Huawei P30 Lite",
            "price": "5800.00"
          }
        ]

      Or you may get a message indicates that the database server is not ready yet, don't worry and try again in 10 seconds.

About

This project shows a simple implementation for an express app with mysql database deployed using docker.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published