Skip to content

Instantly share code, notes, and snippets.

@RebeccaBakels
Last active March 3, 2021 21:16
Show Gist options
  • Save RebeccaBakels/385534d5bc1c22590eb2c0ff00dce880 to your computer and use it in GitHub Desktop.
Save RebeccaBakels/385534d5bc1c22590eb2c0ff00dce880 to your computer and use it in GitHub Desktop.
Allows us to deploy apps in a "container" to run elsewhere
If it can run in Docker it will run anywhere
Container-package an app with dependancies into a standard unit.
Same Envinorment, sanbox projects, it just works
Image-templates for creating an evinorment or a "Snapshot"
Dockerfile-text file that contains a list of steps to deploy
Dockerfile to Image to Container
Blueprint to Snapshot to Instance
Kubernetes used to manage Docker instances
mkdir 'name'
cd into 'name'
npm init -y
npm i express
code .
create src
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
create index.js with basic API point in src
const express = require('express')
const app = express()
app.get('/', (res, req) => {
res.json({message: 'Docker is awesome'})
})
const port = process.env.PORT || 8080
app.listen(port, () => console.log('app listenint on http://localhost:'+port))
///////////////////////////////////////////////////////////////////////////////////
add to "scripts" add "start": "node ./src"
create .dockerignore and .gitignore and add node_modules to both
then create Dockfile in root directory
/////////////////////////////////////////////////////////////////
FROM node:12-alpine3.10
WORKDIR /src/
COPY . . //copies files to the root of the docker image
RUN npm install
ENV PORT=8080
EXPOSE 8080
CMD ["npm", "start"]
////////////////////////////////////////////////////////////////////
on command line:
docker.ps //make sure no images are running
docker build -t 'name':1.0 . //make sure your period is there so it knows to build HERE
docker run -p 5050:8080 'image name'
docker ps
docker kill 'image name'
docker run -p 5050:8080 -v C:\Users\asus\Documents\Projects\docker101\:\src\ 'name of image'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment