Skip to content

Deployment - dockerizing web server and database #12

@stevenabreu7

Description

@stevenabreu7

For the web server, I have the following dockerfile (which is in the repo's root directory). It basically copies all server files to the docker container, then installs packages and runs the server (by default on port 3000) and exposes port 3000 to outside of the docker container.

FROM node:alpine

WORKDIR /usr/src/app

COPY . ./

RUN npm install
RUN npm run build-ts

EXPOSE 3000

CMD ["npm", "start"]

which I build and run with the following:

docker build -t tc-web .
docker run -d -p 3000:3000 --name tc-web tc-web

For the database, I have the following dockerfile. You can change the COPY ./sql-scripts/ ... to wherever the create_db.sql script is (and any other SQL scripts that should be executed when the container is started).

FROM mysql:5

ENV MYSQL_DATABASE JacobsApp
ENV MYSQL_ROOT_PASSWORD root

COPY ./sql-scripts/ /docker-entrypoint-initdb.d/

This one I run with

docker build -t tc-mysql .
docker run -d -p 3306:3306 --name tc-mysql tc-mysql

Feel free to use or change these dockerfiles as you see fit.

So the task now is:

  • write a docker compose script that runs web server and database in a way that the server can read the database.
  • make sure changes to the database are persisted somehow - so we don't lost any data when the docker container is stopped (probably by mounting a volume to the docker container).
  • clean up the repository with the new docker config files and make a pull request!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions