Skip to content

Instantly share code, notes, and snippets.

@richxcame
Last active January 13, 2022 17:41
Show Gist options
  • Save richxcame/ab76ad21f433a4850159d35c4fe8692e to your computer and use it in GitHub Desktop.
Save richxcame/ab76ad21f433a4850159d35c4fe8692e to your computer and use it in GitHub Desktop.
Docker cheat sheet

Docker

Make sure that docker installed on your machine

Create Dockerfile file in root of project

# Dockerfile

# This is image with version that you need.
FROM node:16

# Working directory in host
WORKDIR /usr/src/app

COPY package*.json ./

# Install dependencies
RUN npm install

# Copy all of your files
COPY . .

# Use port number
EXPOSE 3000

# Command to start your app
CMD [ "node", "app.js" ]

Build a container

# -t  target name
# .   to use Dockerfile

docker build -t test-name .

Run a container

# -d  to run docker in background
# -p  to map host port to local port

docker run -d -p 3000:3000 test-name
# or
docker run -dp 3000:3000 test-name

Show all running containers

docker ps

Stop a container

docker stop <container-id>

Remove a container

docker rm <container-id>

Show all images

docker image ls

Remove an image

docker image rm <image-id>

Download an image

docker pull <image-name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment