docker, docker-compose安裝和使用

官方文檔:php

安裝docker: html

https://docs.docker.com/install/linux/docker-ce/centos/mysql

安裝docker-compose:linux

https://docs.docker.com/compose/install/nginx

# 全部docker命令映射都是:local:container

# create container
docker run --name <name> -p 123:123 -d <image> -v local_path:container_path

# if failed, see logs
docker logs <name/id>

# see how many docker containers
docker ps -a

# see networks
docker network ls

# see network detail
docker network inspect <name/id>

# enter a container
docker exec -ti <name/id> bash

# start docker after rebooting
docker start <name/id>

# check status
docker stats [name/id]

# delete container
docker rm <name/id>

docker container rm $(docker container ls -a -q)         # Remove all containers

# image
docker build 

docker image ls -a                             # List all images on this machine
docker image rm <image id>            # Remove specified image from this machine
docker image rm $(docker image ls -a -q)   # Remove all images from this machine
docker login             # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag  # Tag <image> for upload to registry
docker push username/repository:tag            # Upload tagged image to registry
docker run username/repository:tag                   # Run image from a registry
# 4.刪除images,經過image的id來指定刪除誰

docker rmi <image id>

# 想要刪除untagged images,也就是那些id爲<None>的image的話能夠用

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

# 要刪除所有image的話

docker rmi $(docker images -q)

 

docker run 命令解析:
https://www.runoob.com/docker/docker-run-command.htmlsql

 

學習:
https://docs.docker.com/get-started/part3/docker

 

docker-compose.yaml例子centos

version: '3'
services:
    nginx:
        image: nginx:latest
        # 端口映射
        ports:
            - "80:80"
        # 依賴關係 先跑php
        depends_on:
            - "php"
        # 數據卷
        volumes:
            # 映射主機./conf.d目錄到容器/etc/nginx/conf.d目錄
            - "$PWD/conf.d:/etc/nginx/conf.d"
            - "$PWD/html:/usr/share/nginx/html"
        networks:
            - app_net
        # 容器名稱
        container_name: "compose-nginx"
    php:
        build: ./php-mysqli
        # image指定build Dockerfile生成鏡像的名稱
        image: php:7.2-fpm-mysqli
        ports:
            - "9000:9000"
        volumes:
            - "$PWD/html:/var/www/html"
        networks:
            - app_net
        container_name: "compose-php"
    mysql:
        image: mysql:5.7
        ports:
            - "3306:3306"
        # 環境變量
        environment:
            # mysql密碼
            - MYSQL_ROOT_PASSWORD={本身填密碼}
        networks:
            app_net:
                # 固定子網ip,網段必須在子網絡10.10.*.*
                ipv4_address: 10.10.10.1
        container_name: "compose-mysql"
networks:
    # 配置docker network
    app_net:
        driver: bridge
        ipam:
            config:
                # 子網絡
                - subnet: 10.10.0.0/16
docker-compose up
相關文章
相關標籤/搜索