Docker - dev ops

Common Commands

ExampleDescription
docker exec -it <CONTAINER_ID> /bin/shConnect to container's shell

Run command and use output in dockerfile

# Build an image initially and then copy the output to the newly created image
FROM node:16 AS build

WORKDIR /app

COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY . ./
RUN npm run build

FROM nginx:1.19-alpine
COPY --from=build /app/public /usr/share/nginx/html

        

Dockerfile for Svelte static build behind NGINX proxy

FROM node:16 AS build

WORKDIR /app

COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY . ./
RUN npm run build

FROM nginx:1.19-alpine
COPY --from=build /app/public /usr/share/nginx/html
RUN sed -i '9 a \\ttry_files $uri $uri/ /index.html;' /etc/nginx/conf.d/default.conf
        

Get IP of docker container

        docker inspect <container-id>
                

Docker compose examples

See the examples section in docker-compose-examples GitHub repo and on local machine