Skip to content

Instantly share code, notes, and snippets.

@GraySmith00
Last active September 10, 2021 12:13
Show Gist options
  • Save GraySmith00/8b98c687078faaffab64f54306e9306c to your computer and use it in GitHub Desktop.
Save GraySmith00/8b98c687078faaffab64f54306e9306c to your computer and use it in GitHub Desktop.

Basic Commands

build

docker build -t graysmith00/image-name .

run

docker run -p 8000:8000 image-name

list all images

docker image ls

list running containers

docker ps

stop running container

docker stop [container-id]

shell into container

docker exec -it [container-id] sh

List all containers (only IDs)

docker ps -aq

Stop all running containers

docker stop $(docker ps -aq)

Remove all containers

docker rm $(docker ps -aq)

Remove all images

docker rmi $(docker images -q)

React Setup

Dockerfile.dev

FROM node:alpine

WORKDIR "/app"

COPY package.json .
RUN npm install

COPY . .

RUN ["npm", "run", "start"]

Dockerfile

FROM node:alpine as builder
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build

FROM nginx
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html

docker-compose.yml

version: '3'
services:
  client:
    stdin_open: true
    build:
      contenxt: .
      dockerfile: Dockerfile.dev
    ports: "3000:3000"
    volumes:
      - /app/node_modules
      - .:/app
   test:
    stdin_open: true
    build:
      contenxt: .
      dockerfile: Dockerfile.dev
    volumes:
      - /app/node_modules
      - .:/app
    command: ["npm", "run", "test"] 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment