Instantly share code, notes, and snippets.

Embed
What would you like to do?
My Docker Cheatsheet

:WIP:

Docker

Docker Volumes

  • nocopy

The nocopy modifier is for when you are creating a volume and data already exists in the container's path, you can specify if you want that data copied when the volume is created.

    volumes:
        - type: volume
          source: minio_config
          target: /root
          volume:
            nocopy: true

Create a NFS Volume:

docker volume create --driver local --opt type=nfs --opt o=addr=192.168.0.115,rw --opt device=:/opt/nfs --name mongodb_data

Docker Swarm

Inspect

Inspect the Service:

$ docker service inspect my-service
[
    {
        "ID": "abcdef",
        "Version": {
            "Index": 123
        },
        "CreatedAt": "2018-05-30T00:00:00.452848973Z",
        "UpdatedAt": "2018-05-30T00:00:00.457986437Z",
        "Spec": {
            "Name": "my-service",
            "TaskTemplate": {
                "ContainerSpec": {
                ...
                "LogDriver": {
                    "Name": "sumologic",
                    "Options": {
                        "sumo-compress": "false",
                        "sumo-sending-frequency": "500ms",
                        "sumo-url": "https://endpoint.sumologic.com/receiver/..."
                    }
                    ...

Inspect the LogDriver:

$ docker service inspect my-service --format='{{.Spec.TaskTemplate.LogDriver}}'
{sumologic map[sumo-compress:false sumo-sending-frequency:500ms sumo-url:https://endpointsumologic.com/receiver/...]}

Getting only the sumo-url value:

$ docker service inspect my-service -f '{{index .Spec.TaskTemplate.LogDriver.Options "sumo-url"}}'
https://endpoint.sumologic.com/receiver/...

Getting the Swarm Service and Task Name by inspecting the container:

$ docker inspect abc123def --format '{{index .Config.Labels "com.docker.swarm.task.name"}}'
my-app-ui.1.209jdwldi38jd

$ docker inspect abc123def --format '{{index .Config.Labels "com.docker.swarm.node.id"}}'
2093123jahas3d3

$ docker inspect abc123def --format '{{index .Config.Labels "com.docker.swarm.service.name"}}'
my-app-ui

Filter by Container Name and Format by Name:

$ docker ps --filter name=eng-gringotts-api --format '{{.Names}}'
my-app-api_my-service-api.1.qz23ls235fai23iz234zdn1v

Resources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment