Page tree
Skip to end of metadata
Go to start of metadata

Note these commands are tested on the latest versions and will be updated as new versions are released.

Current versions (as of 9/05/2017):  

docker (17.06.1-ce)

docker-compose (1.15.0)

Use "command --help"  to get more information on a command. Examples:

docker ps --help

Usage:  docker ps [OPTIONS]

List containers

Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all
                        states) (default -1)
  -l, --latest          Show the latest created container (includes all
                        states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display numeric IDs
  -s, --size            Display total file sizes

================================================
docker system prune --help

Usage:  docker system prune [OPTIONS]

Remove unused data

Options:
  -a, --all             Remove all unused images not just dangling ones
      --filter filter   Provide filter values (e.g. 'label=<key>=<value>')
  -f, --force           Do not prompt for confirmation
      --volumes         Prune volumes

General Docker commands

CommandDescription
docker versionList information about the docker version and the API version, etc.
docker --versionList limited information
docker eventsThis gets real time docker events from the server.  Options include filter, format, since, and until.  To exit, use Control C

docker ps

docker ps -a

List running containers (-a will list all existing containers)
docker imagesList the images
docker inspect imagenameInspect an image - needs fully qualified name
docker exec -it containername /bin/bashConnect to a running docker container
docker pause / unpausePauses / unpauses the processes within one or more containers.  Note that if a container is paused, it must be unpaused (not started).
docker statsShows running statistics about docker containers.  Note on later versions of docker (tested on 17.12), by default this command will contain the container name rather than the id. 

docker stats --format "table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}"

Docker stats command formatted to be more easily readable
docker system prune

WARNING - this will remove all stopped containers, all networks not used by at least one container, build cache, and all dangling images.  USE WITH CAUTION. Since removing volumes is a destructive event (all data will be lost in the volume), it is not a default operation. To remove volumes, a flag can be passed (--volumes), or the volume prune command used (see volume commands).  Other flags include --all  or -a (to remove ALL unused images), and --force or -f (to override the confirmation prompt).  This can also be used in conjunction with other commands for a complete docker system refresh (stop and remove all containers and prune)

Commands can be piped through grep to narrow the results

Docker-compose commands

CommandDescription
docker-compose versionList information about the docker-compose version
docker-compose --versionList limited information

docker-compose up -d

Start all services defined in the docker-compose file - create and start the container(s)
docker-compose up -d servicenameStart a specific service defined in the docker-compose file
docker-compose psList all running containers in the current docker-compose project directory; including name, command, state, and ports
docker-compose eventsStreams events for containers in the compose project.  This is similar to docker events, but there are no filters allowed other than ---json.  Exit by using Control C
docker-compose imagesSimilar to docker-compose ps; lists the container name and information about the image(s)
docker-compose configValidate and view the compose file complete/combined with other configuration files such as the docker-compose.override.yml
docker-compose logsView the container logs.  Specific containers can be listed.  Use the -t option to show timestamps, and --tail="xx" to  indicate the number of lines to show from the end of the logs for each container.  To follow the log, use the -f option (and control C to end).
docker-compose pause/unpausePauses the running containers.  Note that the unpause (not start) command has to be used in order to restore the containers to their normal state.
docker-compose start/restartStart or restart existing containers
docker-compose stopStop containers (note this does not remove the containers)

docker-compose rm

Remove a specific service/container
docker-compose rm -fvRemove a specific service/container and the volume (use with extreme caution)
docker-compose downStop AND remove containers,networks, volumes, and images created by docker-compose up.  See parameters - by default does not remove volumes


Volume commands

CommandDescription
docker volume lsList existing volumes
docker volume inspect [volume name]Information about the specific environment
docker volume createCreate a volume - there are various parameters to use here
docker volume rm [volume name]Remove a specific unused volume
docker volume pruneRemove all currently unused volumes - use with extreme caution as a container might have been removed (making the volume removable), but the intent may be to reuse the volume with another container.

Network commands

CommandDescription
docker network lsList existing networks
docker network inspect [network name]Information about a specific network
docker network createCreate a network (various parameters are available)
docker network rm [network name]Remove an unused network
docker network pruneRemove all currently unused volumes - use with extreme caution
docker network connectConnect a  network to a container
docker network disconnect

Disconnect a network from a container

Testing



docker-compose top nameof appDisplay running processes
docker stats nameof appdisplay stats on a container (does not work in docker-compose)


docker-compose top usasapp
fayette_usasapp_1
     UID              PID              PPID              C              STIME             TTY              TIME             CMD
-------------------------------------------------------------------------------------------------------------------------------------
root             34417            34388            0                Sep06            ?                00:14:50         /usr/lib/jvm/j
                                                                                                                       ava-8-openjdk-
                                                                                                                       amd64/jre/bin/
                                                                                                                      java -Djava.ut

docker stats fayette_usasapp_1

CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
fayette_usasapp_1   0.13%               1.608GiB / 63.42GiB   2.54%               127MB / 192MB       5.39MB / 0B         0


Examples

docker version
Client:
 Version:      17.06.1-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   874a737
 Built:        Thu Aug 17 22:51:12 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.06.1-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   874a737
 Built:        Thu Aug 17 22:50:04 2017
 OS/Arch:      linux/amd64
 Experimental: false

docker --version
Docker version 17.06.1-ce, build 874a737
==========================================================================================
docker ps
CONTAINER ID        IMAGE                                     COMMAND                  CREATED             STATUS              PORTS                 NAMES
7fe68d95c210        994bd903dd2b                              "catalina.sh run"        12 days ago         Up 8 days           8080/tcp, 44000/tcp   uat1_usasapp_1
8fbe19fb0883        jwilder/nginx-proxy:alpine                "/app/docker-entry..."   13 days ago         Up 8 days           0.0.0.0:80->80/tcp    proxy_proxy_1
0d35a2a79cb8        nginx                                     "nginx -g 'daemon ..."   13 days ago         Up 8 days           80/tcp                proxy_index_1
31670b7f3aa4        eb53a4148083                              "catalina.sh run"        13 days ago         Up 8 days           8080/tcp, 44001/tcp   uat1_uspsapp_1
cdf27f03f618        docker-dev.ssdt.io/usps-live-db:fayette   "/docker-entrypoin..."   13 days ago         Up 8 days           5432/tcp              uat1_uspsdb_1
7a2f60bf67f0        docker-dev.ssdt.io/usas-live-db:fayette   "/docker-entrypoin..."   13 days ago         Up 8 days           5432/tcp              uat1_usasdb_1

docker ps -a
CONTAINER ID        IMAGE                                     COMMAND                  CREATED             STATUS                     PORTS                 NAMES
7fe68d95c210        994bd903dd2b                              "catalina.sh run"        12 days ago         Up 8 days                  8080/tcp, 44000/tcp   uat1_usasapp_1
22c6ed44c4d0        994bd903dd2b                              "catalina.sh run"        12 days ago         Exited (143) 2 hours ago                         test_usasapp_1
226b79168740        docker.ssdt.io/ssdt-postgres:5            "ssdt-entrypoint.s..."   12 days ago         Exited (137) 2 hours ago                         test_usasdb_1
8fbe19fb0883        jwilder/nginx-proxy:alpine                "/app/docker-entry..."   13 days ago         Up 8 days                  0.0.0.0:80->80/tcp    proxy_proxy_1
e3c5a5243ba2        jwilder/docker-gen                        "/usr/local/bin/do..."   13 days ago         Exited (0) 8 days ago                            proxy_index-gen_1
0d35a2a79cb8        nginx                                     "nginx -g 'daemon ..."   13 days ago         Up 8 days                  80/tcp                proxy_index_1
31670b7f3aa4        eb53a4148083                              "catalina.sh run"        13 days ago         Up 8 days                  8080/tcp, 44001/tcp   uat1_uspsapp_1
cdf27f03f618        docker-dev.ssdt.io/usps-live-db:fayette   "/docker-entrypoin..."   13 days ago         Up 8 days                  5432/tcp              uat1_uspsdb_1
7a2f60bf67f0        docker-dev.ssdt.io/usas-live-db:fayette   "/docker-entrypoin..."   13 days ago         Up 8 days                  5432/tcp              uat1_usasdb_1

docker ps | grep usps
31670b7f3aa4        eb53a4148083                              "catalina.sh run"        13 days ago         Up 8 days           8080/tcp, 44001/tcp   uat1_uspsapp_1
cdf27f03f618        docker-dev.ssdt.io/usps-live-db:fayette   "/docker-entrypoin..."   13 days ago         Up 8 days           5432/tcp              uat1_uspsdb_1

==========================================================================================
docker-compose version
docker-compose version 1.15.0, build e12f3b9
docker-py version: 2.4.2
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t  3 May 2016

docker-compose --version
docker-compose version 1.15.0, build e12f3b9
==========================================================================================
docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
docker.ssdt.io/usas-app           pilot               0ec6435ca1d2        5 days ago          588MB
docker.ssdt.io/usas-app           uat                 0ec6435ca1d2        5 days ago          588MB
docker.ssdt.io/usps-app           pilot               bd151f3cf8ff        5 days ago          594MB
docker.ssdt.io/usps-app           uat                 bd151f3cf8ff        5 days ago          594MB
docker.ssdt.io/usps-app           <none>              be5ebd57ec36        6 days ago          594MB
docker.ssdt.io/usps-app           <none>              43fa507afec2        8 days ago          594MB
docker.ssdt.io/usps-app           <none>              c65b8f741bba        12 days ago         594MB
docker.ssdt.io/usas-app           <none>              994bd903dd2b        2 weeks ago         588MB
jwilder/nginx-proxy               alpine              10d86b332e6d        2 weeks ago         51.2MB
docker.ssdt.io/usps-app           <none>              eb53a4148083        2 weeks ago         594MB
docker-dev.ssdt.io/usas-live-db   fayette             cd379841bb57        4 weeks ago         813MB
nginx                             latest              b8efb18f159b        5 weeks ago         107MB
jwilder/docker-gen                latest              4f4702d334a3        5 weeks ago         19.6MB
docker.ssdt.io/ssdt-postgres      5                   a45f1611ebec        5 weeks ago         272MB
docker-dev.ssdt.io/usps-live-db   fayette             a98717c515f0        4 months ago        590MB
docker.ssdt.io/ssdt-utils         latest              6d6bffa72cb1        11 months ago       284MB

docker images | grep usps-app
docker.ssdt.io/usps-app           pilot               bd151f3cf8ff        5 days ago          594MB
docker.ssdt.io/usps-app           uat                 bd151f3cf8ff        5 days ago          594MB
docker.ssdt.io/usps-app           <none>              be5ebd57ec36        6 days ago          594MB

==========================================================================================
 docker inspect docker.ssdt.io/usas-app:pilot
[
    {
        "Id": "sha256:0ec6435ca1d240e969dbdc91592ba808d440b01bbf8304030a028b9ba4c40624",
        "RepoTags": [
            "docker.ssdt.io/usas-app:pilot",
            "docker.ssdt.io/usas-app:uat"
        ],
        "RepoDigests": [
            "docker.ssdt.io/usas-app@sha256:d8c0505d7947e6dcf852c27365f12ffe274d2ee45460265bf4a1f0dce3607610"
        ],
<--and a lot more information-->

docker inspect docker.ssdt.io/usas-app:pilot | grep Author
        "Author": "Dave Smith <smith@nwoca.org>",

==========================================================================================
docker exec -it uat1_uspsdb_1 /bin/bash
root@cdf27f03f618:/#

<--Example to be able to look at the database in a container-->
docker exec -it uat1_uspsdb_1 /bin/bash
root@cdf27f03f618:/# su - postgres
No directory, logging in with HOME=/
$ psql
psql (9.4.5)
Type "help" for help.

postgres=#
==========================================================================================
 docker stats --format "table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}"
NAME                           MEM USAGE / LIMIT     MEM %
matt_usasapp_1                 1.524GiB / 127.9GiB   1.19%
matt_usasdb_1                  6.223MiB / 127.9GiB   0.00%
andreadev_uspsdb_1             3.277MiB / 127.9GiB   0.00%
loridev_uspsdb_1               3.094MiB / 127.9GiB   0.00%

==========================================================================================
docker system prune
WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache 

docker system prune --all --force --volumes

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all volumes not used by at least one container
        - all images without at least one container associated to them
        - all build cache

####USE THE FOLLOWING WITH EXTREME CAUTION - IT IS USED IF YOU NEED TO COMPLETELY CLEAN A DOCKER SYSTEM#####
docker container stop $(docker container ls -a -q) && docker system prune -a -f --volumes

======================================================================================================
 docker events --since '2018-09-08' --filter 'event=start'
2018-09-08T01:00:02.781591655-04:00 container start 5fa3c484b220d181289c104de58e93fa0396444847ab19b8ea01623fb19dcc88 (image=docker.ssdt.io/ssdt-utils, name=keen_fermat)
2018-09-09T01:00:02.308893519-04:00 container start 3f9679fa25aad836f380a42dc788f387fe7effc3567266a88b298e25738b5d8f (image=docker.ssdt.io/ssdt-utils, name=determined_jang)
2018-09-10T01:00:02.423988779-04:00 container start 12439e76463b53eff767127a7dfc3a47caa17b9d31e0dfa0b115a77a6058be26 (image=docker.ssdt.io/ssdt-utils, name=goofy_yonath)
2018-09-11T01:00:02.575341961-04:00 container start dafa834df165512b0e5db80943e69a3733ddad38bed3b00543a4303ad04cd6ff (image=docker.ssdt.io/ssdt-utils, name=goofy_wing)

###Common docker-compose logs syntax
##Last 50 lines of the uspsapp log
docker-compose logs --tail=50 uspsapp
##Follow the usasapp log
docker-compose logs -f usasapp
Ctrl C to end
##Show certain keywords in a log - in this case it is looking for the word loading in the log
docker-compoes logs usasapp | grep 'loading'


  
  • No labels