user695752
user695752

Reputation: 339

dockerize mysql web application

I am trying to dockerize a node.js web app that connects to a mysql database. Just started using docker. Can’t seem to find any definitive answers online on how to configure this. I understand I need to use a “docker-compose.yaml” file and utilize docker-compose. But not sure what info needs to be entered into the yaml file.

Both the node.js app and the mysql server are located on local machine, same machine running docker.

database name is "staff"

Here is one example I came across. But not sure in which directory it should be placed relative to web application. Also, not sure if I am supposed to list the database name in there somewhere.

version: '3'
services:
  web-app:
    build:
      context: .
      dockerfile: web-app/Dockerfile
      ports:
      - 8080:8080
    links:
      - app-db

app-db:
    build:
      context: .
      dockerfile: app-db/Dockerfile

    environment:
    - MYSQL_ROOT_PASSWORD=password
    - MYSQL_DATABASE=Optimize
    ports:
      - 3306:3306

Lastly, how should the containers be structured? Would it be 2 separate containers for the web app and the database or can they be in the same container?

Upvotes: 0

Views: 801

Answers (2)

Pat
Pat

Reputation: 11

I absolutly agree with the previous answer. Docker is made on application level. Thus, every entity should run in a seperate container. Make sure, you get in touch with the technology and try to seperate all your services inside a separated container.

However, you have other options like setting up a vm, lxc or jails. Actually, to get in touch with containerization, I'd like to recommend getting in touch with lxc first.

Upvotes: 0

kopiro
kopiro

Reputation: 709

You don't have clear ideas at all :)

Let's start from beginning: how should the containers be structured?

Absolutely two separate containers on the same network (linked); you have to understand that every container must be separated by its responsibility. Here we have the Business logic in a container and the Database in another one.

Now, you should understand how docker works even before using docker-compose; so please follow this tutorial and come back if you still have problems: https://medium.com/@niratattri/building-a-node-js-application-and-deploying-through-docker-meet-docker-aa8ae677ea12

Upvotes: 1

Related Questions