Docker

docker common commands


run a container

new way

old way

list containers

new way

old way

stop container

new way`

old way

container logs

new way

old way

container ps / top

new way

old way

container start with bash


Network


Misc.

docker-compose

Note: with new Docker compose is built in so use it as sub command docker compose instead of docker-compose

Dockerfile

Comprehensive Example

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0

ARG GO_VER
ARG ALPINE_VER

FROM alpine:${ALPINE_VER} as peer-base
RUN apk add --no-cache tzdata

FROM golang:${GO_VER}-alpine${ALPINE_VER} as golang
RUN apk add --no-cache \
	bash \
	gcc \
	git \
	make \
	musl-dev
ADD . $GOPATH/src/github.com/hyperledger/fabric
WORKDIR $GOPATH/src/github.com/hyperledger/fabric

FROM golang as peer
ARG GO_TAGS
RUN make peer GO_TAGS=${GO_TAGS}

FROM peer-base
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
VOLUME /var/hyperledger
COPY --from=peer /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/msp ${FABRIC_CFG_PATH}/msp
COPY --from=peer /go/src/github.com/hyperledger/fabric/sampleconfig/core.yaml ${FABRIC_CFG_PATH}
EXPOSE 7051
CMD ["peer","node","start"]

private registry

secrets


creating secret


service with secrets


docker stack compose file:

version: "3.1"

services:
    psql:
        image: postgres
        secrets:
            - psql_user
            - psql_password
        environment:
            POSTGRES_PASSWORD_FILE: /run/secrets/psql_password
            POSTGRES_USER_FILE: /run/secrets/psql_user
secrets:
    psql_user:
        file: ./psql_user.txt
    psql_password:
        file: ./psql_password.txt

stacks

docker swarm


node 1

node 2 and 3

making node 2 and 3 managers from node 1

creating a service that is replicated in three nodes


Overlay multi-host networking


Routing mesh

Build X

Docker Deploy

version: "3"
services:
        redis:
                image: redis:alpine
                ports:
                        - "6379"
                networks:
                        - frontend
                deploy:
                        replicas: 2
                        update_config:
                                parallelism: 2
                                delay: 10s
                        restart_policy:
                                condition: on-failure
        db:
                image: postgres:9.4
                volumes:
                        - db-data:/var/lib/postgresql/data
                networks:
                        - backend
                deploy:
                        placement:
                                constraints: [node.role == manager]
        vote:
                image: dockersamples/examplevotingapp_vote:before
                ports:
                        - 5000:80
                networks:
                        - frontend
                depends_on:
                        - redis
                deploy:
                        replicas: 2
                        update_config:
                                parallelism: 2
                        restart_policy:
                                condition: on-failure
        result:
                image: dockersamples/examplevotingapp_result:before
                ports:
                        - 5001:80
                networks:
                        - backend
                depends_on:
                        - db
                deploy:
                        replicas: 1
                        update_config:
                                parallelism: 2
                                delay: 10s
                        restart_policy:
                                condition: on-failure
        worker:
                image: dockersamples/examplevotingapp_worker
                networks:
                        - frontend
                        - backend
                deploy:
                        mode: replicated
                        replicas: 1
                        labels: [APP=VOTING]
                        restart_policy:
                                condition: on-failure
                                delay: 10s
                                max_attempts: 3
                                window: 120s
                        placement:
                                constraints: [node.role == manager]
networks:
        frontend:
        backend:
volumes:
        db-data:

References:

  1. docker buildx
  2. GitHub - docker/buildx: Docker CLI plugin for extended build capabilities with BuildKit
  3. GitHub - moby/buildkit: concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit