docker-cheat-sheet

docker cheat sheet

check images

docker images

pull docker images

docker pull [image name]
docker pull ubuntu

remove docker image

docker rmi [image name]

delete all the images

docker rmi -f $(docker images -aq)

rename docker images

docker tag image-ID [new-name]

remove tag in docker images

docker rmi REPOSITORY:TAG

list all existing container

docker ps -a

list running container

docker ps

run docker image

docker run -t -d --name [image tag] [image name]
docker run -t -d --name latest ubuntu

start container

docker start <CONTAINER_ID> or <CONTAINER_NAMES>
docker start 5c2f4b9516c7
or 
docker start containername

stop container

docker stop [container ID]
docker stop 67a5052f3154

remove container

docker rm [container ID]

delete all containers including its volumes use

docker rm -vf $(docker ps -aq)

Build an image from the Dockerfile

docker build -t [docker image] .

update docke images

 docker build -t REPO:TAG .

How to Run PostgreSQL and pgAdmin Using Docker

create docker-compose.yml file in the directory

  • db port meaning: the ports tag is used to define both host and container ports. It maps port 5432 on the host to port 5432 on the container.
version: '3.8'
services:
  db:
    container_name: postgres_container
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: root
      POSTGRES_DB: test_db
    ports:
      - "5432:5432"
  pgadmin:
    container_name: pgadmin4_container
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: root
    ports:
      - "5050:80"
  adminer:
    container_name: adminer_container
    image: adminer
    restart: always
    ports:
      - 8080:8080

starts and runs the entire app

docker compose up -d

grab the PostgreSQL container id

docker ps -a

image

extract IPAddress on the running container

docker inspect fcc97e066cc8 | grep IPAddress

image

open PgAdmin

image

  • Click Servers > Create > Server to create a new server.

image

  • better write the host with the container name

image

set env variable on linux