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)

General Docker commands

CommandDescription
docker versionList information about the docker version and the API version, etc.
docker --versionList limited information

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 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

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 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 specfied
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


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%




  • No labels