Your First Dockerfile(SCA-cloud test)

Few weeks ago, She Code Africa called for applications for it’s cloud internship. One of the technical assessment was on Docker containers. You can look up the assessment here. Was the test too challenging for you? well, it’s not too late to learn now.

Basically, the whole idea is to run an application from a Docker container. Just like running an app on localhost but this time it’s on Docker environment. Our preferred language is JavaScript and we will be running a Nodejs application from a docker container.

Okay let’s start.

Prerequisites

Step 1: Create a GitHub repository

Step 2: Set up Nodejs Application.

Switch to a branch stable git checkout -b stable and create a folder called docker.

This is what your package.json file should look like.

Note: Replace script object

“scripts”: { 
“test”: “echo \”Error: no test specified\” && exit 1"
},

with

“scripts”: {“start”: “node app.js”
}

Your file structure

docker
| — — node_modules
| — — views
| | — — index.html
| — — .dockerignore
|— — .gitignore
| — App.js
| — — Dockerfile
|— — package-lock.json
|— — package.json

App.js

index.html (inside views folder.)

Step3 : Set up Dockerfile.

Add these codes to your Dockerfile

Step 4: Build Docker image

Run docker build -t dockerdemo where dockerdemo is the name of your image. Run docker run -p 4990:8080 -d dockerdemo

Step 5: Push to GitHub

Step 6: Push to DockerHub

Step 7: Feature Branch (similar to stable branch)

Other things to note based on instruction:

That is it…✌ You can view the repo here

I hope this really helped someone. I appreciate comments and questions where you don’t understand. BYE!

Software developer. Imaginative. I love daring and exploring. The confusion in startups is thrilling and i love it.