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!
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.
which I build and run with the following:
For the database, I have the following dockerfile. You can change the
COPY ./sql-scripts/ ...to wherever thecreate_db.sqlscript is (and any other SQL scripts that should be executed when the container is started).This one I run with
Feel free to use or change these dockerfiles as you see fit.
So the task now is: