lwc:docker

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
lwc:docker [2026/02/28 13:13] John Harrisonlwc:docker [2026/03/01 10:34] (current) John Harrison
Line 29: Line 29:
     *  The ''-v'' removes the associated volumes at the same time.     *  The ''-v'' removes the associated volumes at the same time.
   * When updating images, after pulling and restarting, run ''docker image prune'' to remove the dangling images   * When updating images, after pulling and restarting, run ''docker image prune'' to remove the dangling images
 +  * ''docker ps -a'': see all containers, even the ones that are stopped 
 +  * 
 ==== Watchtower ==== ==== Watchtower ====
   * Watchtower is a container which auto updates Docker containers   * Watchtower is a container which auto updates Docker containers
Line 47: Line 48:
 </code> </code>
   * run watchtower immediately: ''docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --run-once''   * run watchtower immediately: ''docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --run-once''
 +
 +===== Basic Operations =====
 +  * ''docker run'': run container
 +    * use the ''-d'' flag for "detach" i.e. run in background
 +    * use the ''-p'' flag to forward the port i.e. ''-p 9000:80'' maps port 80 in the container to 9000 on the host
 +    * user the ''--name'' flag to name the container (otherwise it's auto generated)
 +  * ''docker stop <ID>''
 +  * ''docker logs <ID>''
 +  * ''docker start <ID>'': restart a container
 +  * ''docker build <DIR_WHERE_Dockerfile_IS_LOCATED>'': build the image
 +    * ''-t'': add name and tag. Ex: ''docker build -t node-app:1.0 .''
 +
 +===== Docker Registry =====
 +  * Docker Hub is the default registry and it is the biggest public registry
 +  * you can store a private or public registry on Docker Hub
 +  * Each application gets its on repo in the registry
 +
 +===== creating a Dockerfile =====
 +  * All dockerfiles start with a parent image or "base image"
 +  * define the base image with ''FROM''
 +  * copy files into the container: ''COPY''
 +    * example: ''COPY package.json /app/''
 +  * set the working directory: ''WORKDIR''
 +    * example: ''WORKDIR /app''
 +  * next come the dependencies: ''RUN <dependencies here>''
 +    * example: ''RUN npm install''
 +  * for the last command in the docker file i.e. start the process: ''CMD''
 +    * example: ''CMD ["node", "server.js"]''
 +