Cyan Hall C H
Created by CyanHall.com. Last updated: 11/25/2020 👉  

1. List docker image

    docker images
  

2. Remove docker image

    docker rmi [IMAGE ID / REPOSITORY]
  

3. Remove all <none> images

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

4. List all docker container

    docker ps -a
  

5. Remove docker container

    docker rm [CONTAINER ID]
  

6. Inspect container

    docker inspect [CONTAINER ID]
  

7. Inspect container ip

    docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' [CONTAINER ID]
  

8. Login to container

    docker exec -it [CONTAINER ID or CONTAINER NAME] bash
  

9. Execute Shell inside container

    docker exec [CONTAINER ID or CONTAINER NAME] [Shell Command]
  

10. Copying files from Docker container to host

    docker cp [CONTAINER ID]:/file/path/within/container /host/path/target
  

11. Build Docker Image

    FROM alpine:latest as certs
RUN apk update && apk upgrade && apk add --no-cache ca-certificates
RUN update-ca-certificates

FROM scratch
# fix x509: certificate signed by unknown authority
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

WORKDIR $GOPATH/src/github.com/Cyanhall/Cyanhall
COPY . $GOPATH/src/github.com/Cyanhall/Cyanhall

EXPOSE 8080
ENTRYPOINT ["./Cyanhall"]
  

12. Build from the source code at current path

    # -t: Repository name (and optionally a tag) for the image
docker build -t [IMAGE NAME] .
  

13. Run DB

    # --name: Name of the container
# -e: Environment variables
# -d: Run in background
# -v: Bind mount a volume
# -p: Publish a container's port(s) to the host
# Postgres environment variables: 
#   POSTGRES_PASSWORD,
#   POSTGRES_USER,
#   read more: https://hub.docker.com/_/postgres
docker run -d --name cyanhall-postgres -v /my/own/datadir:/var/lib/postgresql/data -p 5432:5432 -e POSTGRES_PASSWORD=[password] -e POSTGRES_USER=root postgres
  

14. Run App

    docker run -d -p 8080:8080 --name cyanhall-app --link=cyanhall-postgres:cyanhall-db [IMAGE NAME]
  

15. container Env

    # Inside cyanhall-app container
# env | grep CYANHALL_DB
CYANHALL_DB_ENV_PG_MAJOR=12
CYANHALL_DB_ENV_PGDATA=/var/lib/postgresql/data
CYANHALL_DB_ENV_POSTGRES_USER=root
CYANHALL_DB_PORT_5432_TCP_ADDR=172.17.0.2
CYANHALL_DB_ENV_POSTGRES_PASSWORD=password
CYANHALL_DB_PORT_5432_TCP_PORT=5432
CYANHALL_DB_PORT=tcp://172.17.0.2:5432
CYANHALL_DB_PORT_5432_TCP=tcp://172.17.0.2:5432
CYANHALL_DB_ENV_LANG=en_US.utf8
CYANHALL_DB_PORT_5432_TCP_PROTO=tcp
CYANHALL_DB_ENV_GOSU_VERSION=1.12
CYANHALL_DB_NAME=/cyanhall-postgres/cyanhall-db
CYANHALL_DB_ENV_PG_VERSION=12.3-1.pgdg100+1