Начать. Это бесплатно
или регистрация c помощью Вашего email-адреса
Docker создатель Mind Map: Docker

1. New To Docker

1.1. Use Linux as your base

1.1.1. Use Digital Ocean If you are unsure

1.1.1.1. 01 Sign up using below affiliate link https://m.do.co/c/2e970fcffc6e

1.1.1.2. 02 Create Droplet Using Ubuntu

1.1.1.2.1. Settings That Worked For Light Testing

1.1.1.2.2. Recommend Using a NEW ssh key

1.1.1.3. 03 Follow Docker Instructions

1.1.1.3.1. https://docs.docker.com/engine/install/ubuntu/

1.1.1.3.2. Dcoker Instructions Listed Here for Convenience

2. echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

3. CLI

3.1. Container

3.1.1. start

3.1.1.1. New Container

3.1.1.1.1. docker container run -d -p HOST_PORT:CONTAINER_PORT --restart RESTART_POLICY --name NEW_CONTAINER_NAME --network NETWORK DOCKER_IMAGE_NAME

3.1.1.1.2. Run New Container That Is automatically removed

3.1.1.1.3. Other Options that can be added to docker run

3.1.1.2. Pre-existing Stopped Contianer

3.1.1.2.1. docker container start CONTAINER_NAME

3.1.2. stop

3.1.2.1. Stop Single Container

3.1.2.1.1. docker container stop CONTAINER_NAME

3.1.2.2. Bulk stop all running containers

3.1.2.2.1. docker container stop $(docker container ls -aq)

3.1.3. Remove

3.1.3.1. Remove Single Container

3.1.3.1.1. docker container rm CONTAINER_NAME

3.1.3.1.2. docker container rm CONTAINER_ID

3.1.3.2. Bulk Remove All Containers

3.1.3.2.1. docker container prune

3.1.4. list

3.1.4.1. docker ps

3.1.4.1.1. lists running containers

3.1.4.2. docker ps -a

3.1.4.2.1. lists all containers including stopped containers

3.1.4.3. List Ids Only

3.1.4.3.1. docker container ls -q

3.1.4.3.2. docker container ls -aq

3.1.5. Overriding the Deafult Container Command

3.1.5.1. docker container run -d IMAGE NEW_COMMAND

3.1.6. See Details

3.1.6.1. See Json detailed info

3.1.6.1.1. docker container inspect CONTAINER_NAME

3.1.6.1.2. Additional Notes

3.1.6.2. See selected info

3.1.6.2.1. docker container inspect CONTAINER_NAME --format='{{ .VARIABLE}}'

3.1.6.2.2. example

3.1.6.2.3. Additional Notes

3.2. Images

3.2.1. Create an image

3.2.1.1. From Dockerfile

3.2.1.1.1. with Dockerfile in current directory

3.2.1.1.2. docker build -t REPO_NAME:VERSION_TAG PATH_TO_DIR_OF_DOCKERFILE

3.2.1.2. From Running Container

3.2.1.2.1. docker container commit --change=DOCKERFILE_INSTRUCTION CONTAINER_ID NEW_IMAGE

3.2.1.2.2. Additional Notes

3.2.1.2.3. example

3.2.2. Tag an image

3.2.2.1. Tag an existing image

3.2.2.1.1. docker tag IMAGE_ID REPO:VER

3.2.2.2. Tag an image during the build process

3.2.2.2.1. docker build -t REPO:VER DOCKERFILE_DIR_PATH

3.2.3. See Details of Image

3.2.3.1. See layers

3.2.3.1.1. docker history IMAGE

3.2.3.2. See details

3.2.3.2.1. docker image inspect IMAGE_NAME

3.2.3.3. See selected details

3.2.3.3.1. docker image inspect IMAGE_NAME --format='{{.VARIABLE}}'

3.2.3.3.2. example

3.2.3.3.3. Additional Notes

3.2.4. Downloading an Image

3.2.4.1. docker image pull REPO

3.2.4.2. Example

3.2.4.2.1. docker image pull mysql

3.2.5. Flattening an Image

3.2.5.1. Command List

3.2.5.1.1. 01

3.2.5.1.2. 02

3.2.5.1.3. 03

3.2.5.2. Example

3.2.5.2.1. docker container run -dt --name mynginx nginx docker export mynginx > mynginx.tar cat mynginx.tar | docker import - mynginx:latest

3.2.6. Manual Transfer of Images

3.2.6.1. Instruction

3.2.6.1.1. 01

3.2.6.1.2. 02

3.2.6.1.3. 03

3.2.6.2. Example

3.2.6.2.1. docker save myimg > myimg.tar docker load < myimg.tar

3.3. Registry

3.3.1. Create Registry

3.3.1.1. $ docker run -d -p 5000:5000 --restart always --name registry registry:2

3.3.1.1.1. Runs a registry at port 5000

3.3.1.2. Additional Notes

3.3.1.2.1. Take the comamnd from the official docker hub page https://hub.docker.com/_/registry

3.3.2. Pull From Non Docker Hub Registry

3.3.2.1. docker pull DOMAINNAME:PORT/IMAGE_NAME

3.3.3. Push Image to Non Docker Hub Registry

3.3.3.1. Instruction list

3.3.3.1.1. 01

3.3.3.1.2. 02

3.3.3.2. Example

3.3.3.2.1. docker tag ubuntu:latest localhost:5000/newubuntu docker push localhost:5000/newubuntu

3.3.4. Docker Hub

3.3.4.1. Push to Dockerhub

3.3.4.1.1. Instruction List

3.3.4.1.2. Example

3.3.4.2. Search Dockerhub Images

3.3.4.2.1. docker search --filter FILTER:VALUE REPO_NAME

3.3.4.2.2. Examples

3.3.4.2.3. Additional Notes

3.4. Swarm

3.4.1. Nodes

3.4.1.1. Join A Swarm

3.4.1.1.1. As Leader

3.4.1.1.2. As Worker

3.4.1.2. List Tokens

3.4.1.2.1. As Leader Node

3.4.1.3. Leave swarm

3.4.1.3.1. worker node

3.4.1.4. List nodeas

3.4.1.4.1. docker node ls

3.4.1.5. Setting Node Status in Swarm

3.4.1.5.1. Set to active -

3.4.1.5.2. Set to drain - prevent usage

3.4.1.6. Show details

3.4.1.6.1. docker node inspect NODE_ID

3.4.1.7. Labels

3.4.1.7.1. Add Label

3.4.1.7.2. Inspect Label

3.4.1.7.3. Remove Label

3.4.1.8. Recover Swarm

3.4.1.8.1. docker swarm init --force-new-cluster --advertise-addr $(ifconfig eth0 | grep "inet " | awk '{ print($2)}')

3.4.2. Service

3.4.2.1. Creation

3.4.2.1.1. Replica Mode

3.4.2.1.2. Global Mode

3.4.2.2. Removal

3.4.2.2.1. docker service rm SERVICE_NAME

3.4.2.3. List Current Service make up - container on nodes

3.4.2.3.1. docker service ps SERVICE_NAME

3.4.2.4. Scaling number of replicas

3.4.2.4.1. docker service scale SEVRICE_NAME=NUM_NEW_CONTAINERS

3.4.2.4.2. docker service update --replicas NUM_NEW_CONTAINERS SERVICE_NAME

3.4.2.5. Show Details

3.4.2.5.1. docker service inspect SERVICE_NAME

3.4.2.6. Volumes

3.4.2.6.1. docker service create --name SERVICE_NAME --mount type=volume,source=DOCKER_HOST_VOL_NAME,target=CONTAINER_PATH --network NETWORK_NAME IMAGE

3.4.2.7. Recover

3.4.2.7.1. Run in a new reachable

3.4.3. Security

3.4.3.1. lock swarnm

3.4.3.1.1. instructions

3.4.3.2. Unlock swarm

3.4.3.2.1. docker swarm unlock

3.4.3.3. Get Key

3.4.3.3.1. docker swarm unlock-key

3.4.3.4. Rotate Key

3.4.3.4.1. docker swarm unlock-key --rotate

3.5. Overlay Network

3.5.1. Allows communication for containers across nodes

3.5.2. Create

3.5.2.1. docker network create --driver overlay --opt encrypted NETWORK_NAME

3.5.2.1.1. --opt encrypted

3.5.3. Remove

3.5.3.1. docker network rm NETWORK_NAME

3.6. Docker Information

3.6.1. System Health

3.6.1.1. disk

3.6.1.1.1. Whole Docker System

3.6.1.1.2. Breakdown by Container

3.6.2. System Information

3.6.2.1. docker system info

3.6.3. System events

3.6.3.1. docker system events

3.7. Volumes

3.7.1. create

3.7.1.1. Creating Volume

3.7.1.1.1. docker volume create --name VOLUME_NAME

3.7.1.2. Creating Container and Mapping Volume

3.7.1.2.1. docker container run -dt --name CONTAINER_NAME -v VOLUME_NAME:DIR_NAME IMAGE_NAME

3.7.2. list

3.7.2.1. docker volume ls

3.7.3. See Details

3.7.3.1. Inspect

3.7.3.1.1. docker volume inspect VOL_NAME

3.7.3.2. See contents

3.7.3.2.1. /var/lib/docker/volumes/VOLUME_NAME/_data

3.7.4. Delete

3.7.4.1. docker volume rm VOL_NAME

3.8. Bind Mount

4. Dockerfile Instructions

4.1. Using another docker image

4.1.1. FROM REPOSITORY

4.1.1.1. examples

4.1.1.1.1. FROM ubuntu

4.2. Generic

4.2.1. Instruction Keywords in ALL CAPS

4.2.2. Repository need to be lowercase

4.3. Instructions

4.3.1. FROM

4.3.1.1. Specify the base image

4.3.1.1.1. FROM ARGUMENTS

4.3.1.1.2. FROM ubuntu

4.3.2. RUN

4.3.2.1. Run the following command specified as arguments

4.3.2.1.1. RUN ARGUMENTS

4.3.2.1.2. Example

4.3.2.1.3. Run Additional Commands

4.3.3. CMD

4.3.3.1. Specify he default command

4.3.3.1.1. CMD command

4.3.3.1.2. example

4.3.3.2. Additional notes

4.3.3.2.1. CMD can be overwritten as opposed to ENTRYPOINT

4.3.4. LABEL

4.3.5. EXPOSE

4.3.5.1. Informs docker which port to listen to

4.3.5.1.1. EXPOSE PORTNUMBER

4.3.5.1.2. Additional Notes

4.3.6. ENV

4.3.6.1. sets the environment variable during build and also in running container

4.3.6.1.1. ENV ENV_KEY ENV_VALUE

4.3.6.1.2. Example

4.3.6.1.3. Also has docker run option

4.3.6.1.4. Additional Notes

4.3.7. ADD

4.3.7.1. Copy files

4.3.7.1.1. ADD SRC DST

4.3.7.1.2. Additional Notes

4.3.8. COPY

4.3.8.1. Copy files where directory src is relative to Docker file directory, dst is container destination directory

4.3.8.1.1. COPY SRC_FILE_IN_DIR DST_FILE_CONATINER

4.3.8.1.2. example

4.3.9. ENTRYPOINT

4.3.9.1. Specifies a fixed default command

4.3.9.1.1. ENTRYPOINT Command

4.3.9.1.2. Example

4.3.9.1.3. Additional Notes

4.3.10. VOLUME

4.3.11. USER

4.3.12. HEALTHCHECK

4.3.12.1. Runs a custom command to test the health of container

4.3.12.1.1. Additional Notes

4.3.12.1.2. HEALTHCHECK command

4.3.12.1.3. example

4.3.12.1.4. Additional options

5. Run commands in host as if you wer logged in

5.1. docker container exec -it netstat -ntlp

6. Docker Compose

6.1. Compose Commands

6.1.1. Check Syntax of docker-compose.yml

6.1.1.1. docker compose config

6.1.2. Stop and Remove Container/Networks

6.1.2.1. docker compose down

6.1.3. Stop Containers

6.1.3.1. docker compose stop

6.1.4. Run

6.1.4.1. docker compose up -d

6.1.4.1.1. -d detached mode

6.2. Stack

6.2.1. Run stack

6.2.1.1. docker stack deploy --compose-file NAME_COMPOSE_FILE STACK_NAME

6.2.2. Remove Stack

6.2.2.1. docker stack rm STACK_NAME

7. Docker Templates

7.1. Flags with template support

7.1.1. --hostname

7.1.2. --mount

7.1.3. --env

7.2. Templates

7.2.1. Task

7.2.1.1. Task ID

7.2.1.1.1. .Task.ID

7.2.1.2. Task Name

7.2.1.2.1. .Task.Name

7.2.1.3. Task Slot

7.2.1.3.1. .Task.Slot

7.2.2. Node

7.2.2.1. Node ID

7.2.2.1.1. .Node.ID

7.2.2.2. Node Hostname

7.2.2.2.1. .Node.Hostname

7.2.3. Service

7.2.3.1. Service ID

7.2.3.1.1. .Service.ID

7.2.3.2. Service Name

7.2.3.2.1. .Service.Name

7.2.3.3. Service Labels

7.2.3.3.1. .Service.Labels