Skip to content

Instantly share code, notes, and snippets.

@abelcallejo
Last active February 18, 2022 17:04
Show Gist options
  • Save abelcallejo/aa888b45d2d71a7f798dfdc451d1ed41 to your computer and use it in GitHub Desktop.
Save abelcallejo/aa888b45d2d71a7f798dfdc451d1ed41 to your computer and use it in GitHub Desktop.
Docker container template

Docker whale

Container Template

The stupendously minimal template for building a container.

Step 1: Prepare the working directory

git

git clone git@github.com:you/repository.git hello

Traditionally, it is done like so:

mkdir hello

Step 2: Get inside the working directory

cd hello

Step 3: Make the working directory as a Node package

npm init

Fill in the details like so:

package name: (hello)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository: (https://github.com/you/repository.git)
keywords:
author:
license: (ISC)

Step 4: Install the ExpressJS package

npm install express

Step 5: Write the entry point file

index.js

const express = require( 'express' )
const app = express()
const port = 3000

app.get( '/', ( request, response ) => {
  response.send( 'Hello world!' )
} )

app.listen( port, () => {
  console.log( `Example app listening on port ${port}` )
} )

Step 6: Write the Dockerfile

Dockerfile

# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /hello
COPY . .
RUN yarn install --production
CMD ["node", "index.js"]

Step 7: Build the container image using the Dockerfile

docker build -t hello .

Step 8: Run the container

docker run -dp 80:3000 getting-started

Step 9: Test the running container

Open your web browser and visit the address:

http://localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment