Dockerfile+Docker-compose

Dockerfile

I. Introduction

1.1 dockerfile collection of commonly used commands

image.png

1.2 docker build based on a command to mirror dockerfile

docker build [OPTIONS] PATH | URL | -参数

1.3 parameter options

  • --build-arg = []: Set when the variable image creation;

  • --cpu-shares: cpu using a weight set;

  • --cpu-period: CPU CFS limit cycles;

  • --cpu-quota: limit CPU CFS quota;

  • --cpuset-cpus: CPU id specified use;

  • --cpuset-mems: id specified memory use;

  • --disable-content-trust: ignore check, enabled by default;

  • -f: Dockerfile Specifies the path to be used;

  • --force-rm: mirroring process is provided to remove intermediate container;

  • --isolation: isolation technology using the container;

  • --label = []: Set metadata mirror used;

  • -m: maximum value memory is provided;

  • --memory-swap: Swap to set the maximum memory + swap, "- 1" indicates the swap is not limited;

  • --no-cache: create a mirror of the process does not use the cache;

  • --pull: try to update the new version of the mirror;

  • --quiet, -q: quiet mode, only after the success of an output image ID;

  • --rm: Remove mirror disposed intermediate the container after the success;

  • --shm-size: mount / dev / shm size, the default value is 64M;

  • --ulimit: Ulimit configuration.

  • --tag, -t: image name and label, typically name: tag name or format; may be provided to a plurality of image labels in a build.

  • --network: Default default. RUN setting command during construction of a network model
#例如
FROM centos:7
ARG user # ARG user=root
USER $user
docker build --build-arg user=yhhu .

Here to talk about 1.4 CMD, ENTRYPOINTand RUNthe difference, other related content can be viewed below reference links

  • A Dockerfile can have only one CMD command. (Run run docker, dockerfile CMD if the plurality of instructions exists, only the last instruction .CMD may be designated to take effect docker run command line arguments specifies the program to run in the coverage.)
  • There can be a Dockerfile many RUN command. (Runtime docker buld)
  • ENTRYPOINT command: CMD command is similar, but it will not be docker run command-line parameter to specify the command covered, and these command-line parameters are specified as a parameter to the ENTRYPOINT instruction program; however, when you run docker run use the --entrypoint option, this option can be used as the parameter you want to run a program covering ENTRYPOINT instructions specified;

reference

Docker Series 07-Dockerfile Detailed

Docker-compose

installation method

Official Documents

Simple introduces a method of docker-compose documents

In this example a method for configuring the redis mysql +

A. Docker-compose first determine whether the installation is complete

$ docker-compose --version

Two. Docker-compose common parameters

#版本号
version: "3.1"
#服务列表
services:
  #服务名
  mysql:
    #容器名称
    container_name: mysql-docker
    #使用的镜像
    image: mysql
    #没启动时是否自动重启
    restart: always
    #映射端口    :前的为本地端口,:后的为容器的端口
    ports:
      - "3306:3306"
    #添加环境变量
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      TZ: "Asia/Shanghai"
    #挂载文件目录
    volumes:
      - "./storages/data/mysql:/var/lib/mysql"
      - "./storages/config/my.cnf:/etc/my.cnf"
  redis:
    image: redis
    restart: always
    command: --appendonly yes
    ports:
      - 6379:6379
    volumes:
      - "./storages/data/redis:/data"

Guess you like

Origin www.cnblogs.com/yhhu/p/12089919.html