Skip to content

Instantly share code, notes, and snippets.

@RubMart
Created July 19, 2018 17:28
Show Gist options
  • Save RubMart/0bd493bd1c4ff2eda61d56138667a5ad to your computer and use it in GitHub Desktop.
Save RubMart/0bd493bd1c4ff2eda61d56138667a5ad to your computer and use it in GitHub Desktop.
[Docker cool commands and tools] Some cool tools to Docker. #docker #tips

Docker cool commands

Tail logs

In the first steps of an app you can not configure graylog or complex log processing tools. Search in docker logs is easy:

docker logs -t --tail 1000 my_container

docker logs -t --tail 1000 my_container 2>&1 | grep -i error

In previous example we are searching for error (case-insensitive) in the last 1000 log lines.

Docker postgres/postgis backup

Docker backup command

docker exec -it --env PGPASSWORD=[POSTGRESQL_PASSWORD] database_container pg_dump \
 -h [POSTGRESQL_HOST] -p [POSTGRESQL_PORT] \
 -U [POSTGRESQL_USER] [POSTGRESQL_DATABASE] | gzip -9 > backup.sql.gz

Copy file from host to container

Simple file copy:

docker cp script.js container_name:/app/

Copy file from container

Simple file copy:

docker cp container_name:/app/. .

Cron task in docker-compose

Configuration for run cron tasks in docker. In this example, scripts in cron_tasks_folder will be executed hourly:

version: '3'
services:
  cron:
    image: alpine:3.6
    command: crond -f -l 8
    volumes:
     - ./cron_tasks_folder:/etc/periodic/hourly/:ro

Remove all unused images

Be carefoul with this commands!!! Command to remove all unused images:

docker image prune -a

Command to remove dangling images:

docker rmi $(docker images -q -f dangling=true)

Docker has a command to delete all stopped containers, dangling images, networks, unused volumes and build cache at the same time:

docker system prune -a --volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment