Skip to content

Instantly share code, notes, and snippets.

@bbrother92
Last active September 16, 2019 15:03
Show Gist options
  • Save bbrother92/bc2f256a5e9ed72e82678a3a853760f5 to your computer and use it in GitHub Desktop.
Save bbrother92/bc2f256a5e9ed72e82678a3a853760f5 to your computer and use it in GitHub Desktop.
#docker

Containers

docker ps -as
** list containers, -s is short for --size

docker  logs --details [container-id]
** Fetch the logs of a container

docker top CONTAINER
** Display the running processes of a container

docker container rm [container-id]
** Remove one or more containers

docker attach
** Attach local standard input, output, and error streams to the running process
(if the docker container was started using /bin/bash command, you can access it using attach, if not then you need to execute the command to create a bash instance inside the container using exec. When a container is started using /bin/bash then it becomes the containers PID 1 and docker attach is used to get inside PID 1 of a container. So docker attach < container-id > will take you inside the bash terminal as it's PID 1 as we mentioned while starting the container. Exiting out from the container will stop the container.)

docker exec -it [container-id] bash
** 

docker inspect -f '{{ .Mounts }}' containerid
** list volumes in docker containers

docker container prune
** remove all stopped containers

docker system prune
** will clean up all unused containers, networks, images (both dangling and unreferenced)

Images

docker images -a
** Show all images on this machine

docker rmi <imagename>
** Remove the specified image from this machine

Volumes

docker volume ls
** ls all docker volumes

docker volume prune
** remove all unused local volumes

Docker-compose

WP

version: '3.3'
services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

PMA

version: '3'

services:
  # Database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USERNAME: root
volumes:
  db_data:

Docker Cheat Sheet

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