Skip to content

Instantly share code, notes, and snippets.

@dturton
Forked from zmts/docker.md
Created December 18, 2022 18:07
Show Gist options
  • Save dturton/a41ac6a32b754458079a948a7012e734 to your computer and use it in GitHub Desktop.
Save dturton/a41ac6a32b754458079a948a7012e734 to your computer and use it in GitHub Desktop.
Docker, TypeScript, Node.js

Docker, TypeScript, Node.js

Preconditions:

  • TS application listening port: 7777
|-- dist
|-- src
|-- .dockerignore
|-- Dockerfile
|-- package.json
|-- package-lock.json
`-- tsconfig.json

package.json scripts

"scripts": {
  "build": "tsc",
  "start": "node ./dist/main.js"
}

Dockerfile

FROM node:10-alpine

# update packages
RUN apk update

# create root application folder
WORKDIR /app

# copy configs to /app folder
COPY package*.json ./
COPY tsconfig.json ./
# copy source code to /app/src folder
COPY src /app/src

# check files list
RUN ls -a

RUN npm install
RUN npm run build

EXPOSE 7777

CMD [ "node", "./dist/main.js" ]

Docker commands

Images

Build docker image

docker build -t test-image-name .

Run image in interactive mode

docker run -it -p 7777:7777 test-image-name

Or run image in silent(daemon) mode

docker run -d -p 7777:7777 test-image-name

List all images

docker image ls

Remove all images at once

docker rmi $(docker images -q)

Containers

List all active containers

docker ps

List all active and dead containers

docker ps -a

Stop all running containers

docker stop $(docker ps -a -q)

Delete all stopped containers:

docker rm $(docker ps -a -q)

Other

Install help utils

apt-get install iputils-ping nmap

Jump into container shell

docker exec -it CONTAINER_ID /bin/sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment