I'll work on getting this workflow easier but at the moment this is how you can dockerize your images
- install docker on your pc
- If you're working on windows install WSL2 ( Windows subsystem fo Linux 2 ) too.
- Notice that with docker desktop for windows already comes also the package for docker-composer but if you're working on linux you'll have to install that too.
- once you're done with that, i suggest to install also the Visual Studio Code Docker extension.
-
The
"proxy": "http://localhost:3001"
line into client/package.json it had "localhost" substituted with "backend" resulting in"proxy": "http://backend:3001"
in the client/package-docker.json file. in fact this is the file the Dockerfile is instructed to use as the "package.json" of the containerized app. so, if you change something on the package.json file you also have to change it into package-docker.json in order for it to have effect into the docker image. -
now delete your
node_modules
folder and thepackage-lock.json
files from both the client and the server paths so that they will not be copied into the docker containers, you'll be able to regenerate them using the commandnpm install
bu do so only AFTER you have generated the images.
At the moment this is necessary because the .dockerignore file is not behaving as i expected, it might become unnecessary in the future when i'll get what's the problem -
Open a terminal in the root of the project ( your_directory\SolidarityPurchasingGroup> ) and run the command
docker-compose up --build
, it's going to take a while- PS: Make sure to have docker running in your computer!
- click on the docker icon (the whale with the containers) on the side bar of your VSCode, there you'll be able to find a "CONTAINERS" section with a solidaritypurchasinggroup composer project having 2 running containers:
- solidarity-purchasing-group-frontend
- solidarity-purchasing-group-backend
- both containers should have a small green triangle on their side stating that they are running, you can now go to your browser at link http://localhost:3000 and you'll be able to see our app running.
- you can stop the docker-compose containers by right-clicking the solidaritypurchasinggroup and then selecting compose down
- if images of frontend or backend are present ( you can see them in the "IMAGES" section of the docker VSC extension ) then the ports 3000 and 3001 of your pc will be occupied by them this means that npm start and node server.js or nodemon server.js as you are used to use them into the cient and server directories to start the app on your pc WILL NOT WORK until you remove both images ad you an remove them by right-clicking the label latest under their entry in the IMAGES section and then clicking remove
- use the command
docker-compose push
in the root folder. Both the front and back end images will be pushed in their respective remote docker repositories on docker hub.- PS: notice that you'll need to change the user in <user>/<imagename> that is now setted as binco97 with your nickname on docker hub.