Skip to content

Docker Command Reference

Darius Dzien edited this page Mar 25, 2024 · 10 revisions

Below are some basic Docker commands. More complete information is available on the Docker website.

Container management

Create and run the required services in containers:

docker compose up

Stop and remove containers and networks:

docker compose down

Restart a service:

docker compose restart mysql

Restart all services:

docker compose restart

General info

View stats on running containers:

docker stats

List containers:

docker compose ps

List images:

docker image ls

List networks:

docker network ls

View Docker disk usage:

docker system df --verbose

Running commmands in containers

Execute a command in a running container:

docker compose exec elasticsearch7 ...

Fire up a bash shell within a container:

docker compose exec elasticsearch7 bash

Housekeeping

Remove stopped containers, dangling images, unused networks, etc.

docker system prune

Recreate an Elasticsearch cluster

Certain features require an active trial license, which is valid for 30 days. If your license expires, you will need to rebuild your local cluster:

  1. Shut everything down:

    docker compose down (or Ctrl-C)

  2. Force-remove the relevant Elasticsearch container & volume:

    docker compose rm -f elasticsearch7 ; docker volume rm search-services_es_7_data

  3. Start everything up again:

    docker compose up

  4. Verify that a new license has been applied:

    curl localhost:9200/_license
    {
      "license" : {
        "status" : "active",
        "type" : "trial",
        ...
      }
    }

(NB: The Kibana web interface of the locally running Elasticsearch container is usually available at localhost:5601.)

  1. In the search-gov root directory, rebuild your Elasticsearch indices:
rake usasearch:elasticsearch:create_indexes
rake 'usasearch:elasticsearch:index_all[BoostedContent+FeaturedCollection+FederalRegisterDocument+IndexedDocument+NewsItem+SaytSuggestion]'

Troubleshooting

Container exited with code 137

Exit code 137 indicates that a container was killed after it ran out of memory. This can usually be resolved by increasing the memory allotted to your Docker containers (in Docker Desktop: Preferences > Resources > Advanced).

Burn it all down and start from scratch

NOTE: The commands below will take quite a while to run. Use only when under extreme duress.

# Purge data stored in Docker volumes:
docker compose down -v

# Recreate the images w/o using caches
docker compose build --no-cache 

# Recreate containers
docker compose up --force-recreate