My solution to She Code Africa Cloud School - Technical Assesment(Exercise 1).
- link to my docker hub repository - https://hub.docker.com/r/mariehposa/sca_cloud_school_application
These instructions will get you a copy of the project up and running on your local machine.
-
Checkout to
stable
branch. -
Inside the
docker
folder, Create apackage.json
file and add the following code.
{
"name": "sca_app",
"version": "1.0.0",
"description": "create a dockerfile on Nodejs project",
"author": "Mariam Adedeji",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.16.1"
}
}
- Create a node.js app in the
server.js
file using express. This file should contain the following code.
'use strict';
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Welcome to SCA Cloud School Application');
});
app.listen(3000, () => console.log('Server ready'))
-
Run
npm install
to install the packages listed in thepackage.json
file. -
Create a
Dockerfile
with the following content.
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
-
Download and installed Docker Desktop Installer and wsl_update.
-
Run the following code on shell to build the image.
docker build -t image .
For example:
docker build -t sca_cloud_school_application .
- Run the following to run a container from the image.
docker run -d -p 3000:3000 --name username image
For example:
docker run -d -p 3000:3000 --name sca-app sca_cloud_school_application
-
Make your changes and checkout to
feature
branch. -
Update the
line 6
ofserver.js
with the following:
res.send('Welcome to SCA Cloud School Application , this is my first assessment');
- Run the following code on shell to build the image.
docker build -t image .
- Run the following to run a container from the image.
docker run -d -p 3000:3000 --name username image
The image is running in the Docker Desktop
The app is running on port 3000
- Use the
docker tag
to give the image a new name.
docker tag image username/tag-name
For example
docker tag sca_cloud_school_application mariehposa/sca_cloud_school_application
- Use the
docker hub
to push it to Docker Hub.
docker push YOUR-USER-NAME/tag-name
For example
docker push mariehposa/sca_cloud_school_application
- https://flaviocopes.com/docker-dockerfiles/
- https://flaviocopes.com/docker-node-container-example/
- https://flaviocopes.com/docker-hub/
- She Code Africa