Skip to content

Instantly share code, notes, and snippets.

@Pushplaybang
Last active October 7, 2018 19:37
Show Gist options
  • Select an option

  • Save Pushplaybang/974ff65a17014b37aaafd5f5bcc9e0e2 to your computer and use it in GitHub Desktop.

Select an option

Save Pushplaybang/974ff65a17014b37aaafd5f5bcc9e0e2 to your computer and use it in GitHub Desktop.

Revisions

  1. Pushplaybang revised this gist Oct 7, 2018. No changes.
  2. Pushplaybang revised this gist Oct 7, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions docker-basics.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # MY Docker Cheat Sheet
    a breif selection of essential commands, tips and notes about working with docker, as a personal reference. use at your own risk.

    ## Working with containers

    create and start a container
  3. Pushplaybang revised this gist Oct 7, 2018. 1 changed file with 23 additions and 5 deletions.
    28 changes: 23 additions & 5 deletions docker-basics.md
    Original file line number Diff line number Diff line change
    @@ -33,10 +33,11 @@ Exiting an interactive session can usually be accomplished `cmd+c` will exit, if
    ## Dockerfile

    - `FROM` : specifty a base image to start from
    - `WORKDIR` :
    - `COPY` :
    - `RUN` :
    - `CMD` :
    - `LABEL` : add arbitrary labels, such as `author` with `author=<you-name>`
    - `WORKDIR` : specify a working directory in the container (all commands after, use this as root)
    - `COPY` : copy somePath into the container working directory
    - `RUN` : run arbitrary commands
    - `CMD` : set an initial start command for when your container builds

    Here is an example Dockerfile
    ```sh
    @@ -50,9 +51,26 @@ RUN apk add --update redis
    CMD ["redis-server"]
    ```

    this is a very basic container, here's another, thats slightly more complete:

    ```sh
    FROM node:alpine
    LABEL author="my-docker-id"

    WORKDIR /usr/app

    COPY ./package.json ./
    RUN npm install
    COPY ./ ./

    CMD ['npm', 'start']
    ```
    as each instruction is cached, the order is important, to avoid unneccessary rebuild steps and cache busting.


    ## Building containers
    after creating your `Dockerfile` run the following in your project dir:
    - `docker build -t <username/name> .`

    not that this will name your build with the `<username/name> .`
    not that this will name your build with the `<username/name> .` . then run the following to start that container, notice we're parsing in the `-p` flag to specify the port, and are able to run the container by name, rather than id.
    - `docker run -p <external-port>:<container-port> <container-id or name>`
  4. Pushplaybang revised this gist Oct 7, 2018. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion docker-basics.md
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,14 @@ run a command in a running contianer (optionally interactive)

    Exiting an interactive session can usually be accomplished `cmd+c` will exit, if not try `ctrl+d`, or simply type `exit`

    ## Building containers
    ## Dockerfile

    - `FROM` : specifty a base image to start from
    - `WORKDIR` :
    - `COPY` :
    - `RUN` :
    - `CMD` :

    Here is an example Dockerfile
    ```sh
    # use a base image
    @@ -43,6 +50,7 @@ RUN apk add --update redis
    CMD ["redis-server"]
    ```

    ## Building containers
    after creating your `Dockerfile` run the following in your project dir:
    - `docker build -t <username/name> .`

  5. Pushplaybang revised this gist Oct 7, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions docker-basics.md
    Original file line number Diff line number Diff line change
    @@ -45,3 +45,6 @@ CMD ["redis-server"]

    after creating your `Dockerfile` run the following in your project dir:
    - `docker build -t <username/name> .`

    not that this will name your build with the `<username/name> .`
    - `docker run -p <external-port>:<container-port> <container-id or name>`
  6. Pushplaybang revised this gist Oct 7, 2018. 1 changed file with 18 additions and 2 deletions.
    20 changes: 18 additions & 2 deletions docker-basics.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@

    ## Working with containers

    create and start a container
    - `docker run [-a] <container-name> <override>`
    @@ -28,4 +28,20 @@ forcefully, and immediately, stop a container
    run a command in a running contianer (optionally interactive)
    - `docker exec [-it] <container-id> <command>`

    Exiting an interactive session can usually be accomplished `cmd+c` will exit, if not try `ctrl+d`, or simply type `exit`
    Exiting an interactive session can usually be accomplished `cmd+c` will exit, if not try `ctrl+d`, or simply type `exit`

    ## Building containers
    Here is an example Dockerfile
    ```sh
    # use a base image
    FROM alpine

    # dl and install deps
    RUN apk add --update redis

    # tell it what to do when it starts
    CMD ["redis-server"]
    ```

    after creating your `Dockerfile` run the following in your project dir:
    - `docker build -t <username/name> .`
  7. Pushplaybang revised this gist Oct 7, 2018. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions docker-basics.md
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,31 @@


    create and start a container
    `docker run [-a] <container-name> <override>`
    - `docker run [-a] <container-name> <override>`

    essentially runs the following two commands
    `docker create <container-name> <override>`
    `docker start [-a] <container-id>`
    - `docker create <container-name> <override>`
    - `docker start [-a] <container-id>`

    list all running containers
    `docker ps`
    - `docker ps`

    list all containers
    `docker ps --all`
    - `docker ps --all`

    delete everything
    `docker system prune`
    - `docker system prune`

    output logs for a running container
    `docker logs <container-id>`
    - `docker logs <container-id>`

    gracefully stop a running container
    `docker stop <container-id>`
    - `docker stop <container-id>`

    forcefully, and immediately, stop a container
    `docker kill <container-id>`
    - `docker kill <container-id>`

    run a command in a running contianer (optionally interactive)
    `docker exec [-it] <container-id> <command>`
    - `docker exec [-it] <container-id> <command>`

    Exiting an interactive session can usually be accomplished `cmd+c` will exit, if not try `ctrl+d`, or simply type `exit`
  8. Pushplaybang created this gist Oct 7, 2018.
    31 changes: 31 additions & 0 deletions docker-basics.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@


    create and start a container
    `docker run [-a] <container-name> <override>`

    essentially runs the following two commands
    `docker create <container-name> <override>`
    `docker start [-a] <container-id>`

    list all running containers
    `docker ps`

    list all containers
    `docker ps --all`

    delete everything
    `docker system prune`

    output logs for a running container
    `docker logs <container-id>`

    gracefully stop a running container
    `docker stop <container-id>`

    forcefully, and immediately, stop a container
    `docker kill <container-id>`

    run a command in a running contianer (optionally interactive)
    `docker exec [-it] <container-id> <command>`

    Exiting an interactive session can usually be accomplished `cmd+c` will exit, if not try `ctrl+d`, or simply type `exit`