Skip to content

Instantly share code, notes, and snippets.

@gaborpinterweb
Last active November 7, 2023 14:21
Show Gist options
  • Select an option

  • Save gaborpinterweb/4cfcc69fde438c72e3ef8d2cc3887de9 to your computer and use it in GitHub Desktop.

Select an option

Save gaborpinterweb/4cfcc69fde438c72e3ef8d2cc3887de9 to your computer and use it in GitHub Desktop.

Revisions

  1. Gábor Pintér revised this gist Dec 26, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion DOCKER.md
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,7 @@ Reference: [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nod
    | `docker run -p 49160:8080 -d username/repo:tag` | Run image |
    | `docker ps` | List containers |
    | `docker stop containerId` | Stop running container |
    | `docker push username/repo:tag` | Push image to Docker Hub |

    ## Services and tasks

    @@ -57,4 +58,4 @@ Just remember that only swarm managers like myvm1 execute Docker commands; worke
    | `docker stack ps appname` | List tasks |
    | `eval $(docker-machine env -u)` | Unset `docker-machine` environment vars in current shell |
    | `docker-machine start <machine-name>` | Restart machine |

    | `docker swarm join-token worker` | Get join-token of current swarm for workers (issued by manager |
  2. Gábor Pintér revised this gist Dec 26, 2017. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion DOCKER.md
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,20 @@ Reference: [Get Started, Part 3: Services](https://docs.docker.com/get-started/p

    ## Swarms

    Just remember that only swarm managers like myvm1 execute Docker commands; workers are just for capacity. Let's deploy the app on a swarm cluster.

    | Command | Description |
    | - | - |
    | `docker swarm init` | Initialize a swarm |
    | `docker swarm init` | Initialize a swarm |
    | `docker-machine create --driver virtualbox myvm1` | Create a Virtual Machine |
    | `docker-machine ls` | List Virtual Machines |
    | `docker-machine ssh <myvm1> "docker swarm init --advertise-addr <myvm1 ip>"` | Command VM to become a swarm manager |
    | `docker-machine ssh myvm1 "docker node ls"` | List nodes in the swarm managed by myvm1 |
    | `docker swarm leave` | Leave swarm (node) |
    | `docker-machine env myvm1` | Get command to configure shell to talk to VM |
    | `eval $(docker-machine env myvm1)` | Configure shell to talk to VM (macOS) |
    | `docker stack deploy -c docker-compose.yml appname` | Deploy the app on current machine (VM) |
    | `docker stack ps appname` | List tasks |
    | `eval $(docker-machine env -u)` | Unset `docker-machine` environment vars in current shell |
    | `docker-machine start <machine-name>` | Restart machine |

  3. Gábor Pintér revised this gist Dec 25, 2017. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions DOCKER.md
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ Image -> Container (called Task if it's in a Service) -> Service -> Stack -> Swa
    - **[Container](https://docs.docker.com/glossary/?term=container)**: A container is a runtime instance of a docker image.
    - **[Service](https://docs.docker.com/glossary/?term=service)**: A service is the definition of how you want to run your application containers in a swarm (a.k.a.: containers in production). At the most basic level a service defines which container image to run in the swarm and which commands to run in the container. To define, run, and scale services just write a `docker-compose.yml` file.
    - **[Task](https://docs.docker.com/glossary/?term=task)**: A single container running in a service is called a task.
    - **[Swarm](https://docs.docker.com/glossary/?term=swarm)**: A swarm is a group of machines that are running Docker and joined into a cluster.
    - **[Node](https://docs.docker.com/glossary/?term=node)**: The machines in a swarm can be physical or virtual. After joining a swarm, they are referred to as nodes.

    ## Images and containers

    @@ -24,7 +26,7 @@ Reference: [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nod
    | `docker ps` | List containers |
    | `docker stop containerId` | Stop running container |

    ## Swarms, services and tasks
    ## Services and tasks

    Reference: [Get Started, Part 3: Services](https://docs.docker.com/get-started/part3/)

    @@ -35,4 +37,11 @@ Reference: [Get Started, Part 3: Services](https://docs.docker.com/get-started/p
    | `docker stack rm appname` | Take stack down |
    | `docker swarm leave --force` | Take swarm down |
    | `docker service ls`| List services |
    | `docker service ps getstartedlab_web` | List tasks |
    | `docker service ps getstartedlab_web` | List tasks |

    ## Swarms

    | Command | Description |
    | - | - |
    | `docker swarm init` | Initialize a swarm |
    | `docker swarm init` | Initialize a swarm |
  4. Gábor Pintér revised this gist Dec 25, 2017. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions DOCKER.md
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,12 @@

    ## Terminology

    Image -> Container (called Task if it's in a Service) -> Service -> Stack -> Swarm

    - **[Image](https://docs.docker.com/glossary/?term=image)**: An ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime. Portable Docker images are defined by something called a `Dockerfile`.
    - **[Container](https://docs.docker.com/glossary/?term=container)**: A container is a runtime instance of a docker image.
    - **[Service](https://docs.docker.com/glossary/?term=service)**: A service is the definition of how you want to run your application containers in a swarm (a.k.a.: containers in production). At the most basic level a service defines which container image to run in the swarm and which commands to run in the container. To define, run, and scale services just write a `docker-compose.yml` file.
    - **[Task](https://docs.docker.com/glossary/?term=task)**: A single container running in a service is called a task.

    ## Images and containers

    @@ -21,15 +24,15 @@ Reference: [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nod
    | `docker ps` | List containers |
    | `docker stop containerId` | Stop running container |

    ## Services
    ## Swarms, services and tasks

    Reference: [Get Started, Part 3: Services](https://docs.docker.com/get-started/part3/)

    | Command | Description |
    | - | - |
    | `docker swarm init` | Initialize a swarm |
    | `docker stack deploy -c docker-compose.yml appname` | Deploy a new stack or update an existing stack |
    | `docker stack rm appname` | Take app down |
    | `docker stack rm appname` | Take stack down |
    | `docker swarm leave --force` | Take swarm down |
    | `docker service ls`| List services |
    | `docker service ps getstartedlab_web` | List tasks |
  5. Gábor Pintér revised this gist Dec 24, 2017. 2 changed files with 26 additions and 10 deletions.
    17 changes: 7 additions & 10 deletions DOCKER.md
    Original file line number Diff line number Diff line change
    @@ -3,30 +3,27 @@
    ![Docker](https://www.docker.com/sites/default/files/social/docker_twitter_share.png)

    ## Terminology
    Portable Docker images are defined by something called a `Dockerfile`.

    - **[Image](https://docs.docker.com/glossary/?term=image)**: An ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime.
    - **[Image](https://docs.docker.com/glossary/?term=image)**: An ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime. Portable Docker images are defined by something called a `Dockerfile`.
    - **[Container](https://docs.docker.com/glossary/?term=container)**: A container is a runtime instance of a docker image.
    - **[Service](https://docs.docker.com/glossary/?term=service)**: A service is the definition of how you want to run your application containers in a swarm (a.k.a.: containers in production). At the most basic level a service defines which container image to run in the swarm and which commands to run in the container. To define, run, and scale services just write a `docker-compose.yml` file.

    ## Images and containers

    For more fun see: [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/)
    Reference: [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/)

    | Command | Description |
    | - | - |
    | `docker image ls` | List images in the local registry |
    | `docker build -t <your username>/node-web-app:tag .` | Build Docker image |
    | `docker build -t username/repo:tag .` | Build Docker image |
    | `docker images` | List images |
    | `docker run -p 49160:8080 -d <your username>/node-web-app:tag` | Run image |
    | `docker run -p 49160:8080 -d username/repo:tag` | Run image |
    | `docker ps` | List containers |
    | `docker stop containerId` | Stop running container |

    ## Services

    > "Services are really just “containers in production.” A service only runs one image, but it codifies the way that image runs—what ports it should use, how many replicas of the container should run so the service has the capacity it needs, and so on. Scaling a service changes the number of container instances running that piece of software, assigning more computing resources to the service in the process.
    > Luckily it’s very easy to define, run, and scale services with the Docker platform – just write a docker-compose.yml file."m
    For more fun see: [Get Started, Part 3: Services](https://docs.docker.com/get-started/part3/)
    Reference: [Get Started, Part 3: Services](https://docs.docker.com/get-started/part3/)

    | Command | Description |
    | - | - |
    19 changes: 19 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    version: "3"
    services:
    web:
    # replace username/repo:tag with your name and image details
    image: username/repo:tag
    deploy:
    replicas: 5
    resources:
    limits:
    cpus: "0.1"
    memory: 50M
    restart_policy:
    condition: on-failure
    ports:
    - "80:80"
    networks:
    - webnet
    networks:
    webnet:
  6. Gábor Pintér revised this gist Dec 24, 2017. 2 changed files with 47 additions and 1 deletion.
    28 changes: 27 additions & 1 deletion DOCKER.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,32 @@
    # Docker cheatsheet

    ## Get Started, Part 3: Services
    ![Docker](https://www.docker.com/sites/default/files/social/docker_twitter_share.png)

    ## Terminology
    Portable Docker images are defined by something called a `Dockerfile`.

    - **[Image](https://docs.docker.com/glossary/?term=image)**: An ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime.
    - **[Container](https://docs.docker.com/glossary/?term=container)**: A container is a runtime instance of a docker image.

    ## Images and containers

    For more fun see: [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/)

    | Command | Description |
    | - | - |
    | `docker image ls` | List images in the local registry |
    | `docker build -t <your username>/node-web-app:tag .` | Build Docker image |
    | `docker images` | List images |
    | `docker run -p 49160:8080 -d <your username>/node-web-app:tag` | Run image |
    | `docker ps` | List containers |

    ## Services

    > "Services are really just “containers in production.” A service only runs one image, but it codifies the way that image runs—what ports it should use, how many replicas of the container should run so the service has the capacity it needs, and so on. Scaling a service changes the number of container instances running that piece of software, assigning more computing resources to the service in the process.
    > Luckily it’s very easy to define, run, and scale services with the Docker platform – just write a docker-compose.yml file."m
    For more fun see: [Get Started, Part 3: Services](https://docs.docker.com/get-started/part3/)

    | Command | Description |
    | - | - |
    20 changes: 20 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # Dockerfile for a Node.js application
    FROM node:carbon

    # Create app directory
    WORKDIR /usr/src/app

    # Install app dependencies
    # A wildcard is used to ensure both package.json AND package-lock.json are copied
    # where available (npm@5+)
    COPY package*.json ./

    RUN npm install
    # If you are building your code for production
    # RUN npm install --only=production

    # Bundle app source
    COPY . .

    EXPOSE 8080
    CMD [ "npm", "start" ]
  7. Gábor Pintér renamed this gist Dec 24, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md → DOCKER.md
    Original file line number Diff line number Diff line change
    @@ -6,5 +6,7 @@
    | - | - |
    | `docker swarm init` | Initialize a swarm |
    | `docker stack deploy -c docker-compose.yml appname` | Deploy a new stack or update an existing stack |
    | `docker stack rm appname` | Take app down |
    | `docker swarm leave --force` | Take swarm down |
    | `docker service ls`| List services |
    | `docker service ps getstartedlab_web` | List tasks |
  8. Gábor Pintér created this gist Dec 24, 2017.
    10 changes: 10 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # Docker cheatsheet

    ## Get Started, Part 3: Services

    | Command | Description |
    | - | - |
    | `docker swarm init` | Initialize a swarm |
    | `docker stack deploy -c docker-compose.yml appname` | Deploy a new stack or update an existing stack |
    | `docker service ls`| List services |
    | `docker service ps getstartedlab_web` | List tasks |