Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker Series 13: container choreography (1)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. The basis of container orchestration 1. The concept of container orchestration can specify that the programs in each container are dependent. For example, if a web service can only be run when the mysql is normal, then the web container depends on the mysql container. Only when the web container starts normally, the web container can be started. 2. Container layout tools docker composek8sk3s 2, compose details 1. What is composeDocker Compose? the managed container is divided into three layers. All the files (docker-compose.yml) under the Docker Compose running directory of project (project), service (service) and container (container) constitute a project. A project contains multiple services, each of which defines the images, parameters and dependencies of container operation. A service can include multiple container instances 2 and install compse.

Method 1: put this file in / usr/local/bin using the conpose file provided

Method 2: use the installation packages in the epel and download sources

1) configure yum source

[root@host1 ~] # cat / etc/yum.repos.d/epel.repo [epel] name=epelbaseurl= https://mirrors.tuna.tsinghua.edu.cn/epel/7Server/x86_64/enabled=1gpgcheck=0

2) install docker-compose

Detailed explanation of [root@host1] # yum install docker-compose-y3 and compose parameters

Let's first look at a sample dyml file.

Parameter 1:buildbuild, which specifies the path to the folder where Dockerfile is located. Compose will use it to automatically build the image and then use it to start the service container. It can also be a relative path, which can be read to Dockerfile as long as the context is determined.

The parameter 2:context is used to specify the working directory of the dockerfile file, which is a sub-option of build, the parameter 3:dockerfile, which specifies a specific dockerfile for mirroring, and this is a sub-option of build, the 4:ARGS setting variable, which is only used in the build process. This is a sub-option of build, the parameter 5:labels, which is a sub-option of build to specify the metadata parameter 6:shm_size in the build process, which is a sub-option of build. Control the parameter configuration of build-based images / dev/shm is the mapping of physical memory in the system in linux. It is much more efficient to use / dev/shm to manipulate files. When I optimize the system, I often use the parameter 7:command to use command to override the default commands executed after the container starts.

The parameter 8:imageimage is the image name or ID of the specified service. If the image does not exist locally, Compose will try to pull the image. Image: redisimage: ubuntu:14.04image: tutum/influxdbimage: example-registry.com:4000/postgresqlimage: a4bc65fd parameter 9:container_name can use this tag to specify the container name parameter 10:depends_on. This tag solves the problem of container dependency and startup sequence case: the following container starts the redis and db services first, and then starts the web service:

Parameter 11:dns specifies the address of the DNS server dns: 8.8.8.8dns:-8.8.8.8-9.9.9.9 Parameter 12:dns_search sets the search domain dns_search: example.comdns_search:-dc1.example.com-dc2.example.com parameter 13:tmpfs mounts the temporary directory to the container internal tmpfs:-/ run-/ tmp parameter 14:entrypoint is used to override the definition entrypoint in Dockerfile: A file dedicated to storing variables can be defined in the-php-- d-zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so-- d-memory_limit=-1-vendor/bin/phpunit parameter 15:env_filedocker-compose.yml. If a profile is specified through docker-compose-f FILE, the path in env_file uses the profile path. If a variable name conflicts with the environment directive, the latter shall prevail. Env_file: -. / common.env -. / apps/web.env-/ opt/secrets.env parameter 16:environment is used to set image variables. It can save variables to the image, that is, the launched container will also contain these variable settings, which is the biggest difference from arg. Like the ENV instruction in Dockerfile, environment keeps variables in mirrors and containers all the time, similar to the effect of docker run-e. Environment:RACK_ENV: developmentSHOW: 'true'SESSION_SECRET:

Environment:

-RACK_ENV=development

-SHOW=true

-SESSION_SECRET

# Parameter 17 docker-compose.yml expose17 this tag is the same as the EXPOSE directive in Dockerfile to specify the exposed port, but only as a reference * in fact, the port mapping of docker-compose.yml also needs a label such as ports.

Expose:

"3000"8000" parameter 18:external_links in order to enable Compose to connect to these containers that are not defined in docker-compose.yml, external_links can connect containers in the Compose project to those containers outside the project configuration, the external_links:- redis_1- project_db_1:mysql- project_db_1:postgresql parameter 19:extra_hosts adds the hostname tag Is to add some records to the / etc/hosts file extra_hosts:- "somehost:162.242.195.82"-"otherhost:50.31.209.229" tag 20:labels to add metadata to the container It has the same meaning as Dockerfile's LABEL directive: labels:com.example.description: "Accounting webapp" com.example.department: "Finance" com.example.label-with-empty-value: "labels: -" com.example.description=Accounting webapp "-" com.example.department=Finance "-" com.example.label-with-empty-value "tag 21:linksdepends_on, that tag solves the startup sequence problem, and this tag solves the container connection problem. The same effect as Docker client's-- link, which connects to containers in other services. The links:- db- db:database- redis tag 22:logging is used to configure the logging service. Logging:driver: syslogoptions:syslog-address: "tcp://192.168.0.42:123" tag 23:pid container using this tag will be able to access and manipulate the namespaces of other containers and hosts. Pid: "host": sets the PID mode to the host PID mode to share the process namespace with the host system. Label 24:ports the label of the mapping port. Use the HOST:CONTAINER format or just specify the port of the container, and the host will randomly map the port. When using HOST:CONTAINER format to map ports, if you use container ports less than 60, you may get the wrong result because YAML will parse xx:yy as a number format of 60. Therefore, it is recommended to use the string format. The label 25:security_opt overrides the default label for each container. Simply put, it is a label that manages all services. For example, set the user tag value of all services to USER. The security_opt:-label:user:USER-label:role:ROLE tag 26:stop_signal sets another signal to stop the container. The SIGTERM stop container is used by default. The label 27:volumes mounts a directory or an existing data volume container can directly use the format [HOST:CONTAINER], or [HOST:CONTAINER:ro], where the data volume is read-only Compose's data volume specified path can be a relative path, using. Or... To specify a relative directory. Label 28:volumes_from optional parameters for mounting data volumes from other containers or services are: ro or: rw. The former means that the container is read-only, and the latter means that the container is readable and writable to the data volume. By default, it is readable and writable. Volumes_from:-service_name-service_name:ro-container:container_name-container:container_name:rw tag 29:cap_add, cap_drop add or remove a container's kernel function tag 30:cgroup_parent specifies the parent cgroup of a container. Label 31:devices device mapping list. Similar to the-- device parameter of Docker client. Tag 32:extends this tag can extend another service, the extension content can be from the current file, or from other files of the same service, the later will selectively overwrite the original configuration. The extends:file: common.yml service: webapp tag 33:network_mode sets the network mode similar to the-net parameter of Docker client There is only relatively one more service: [service name] format network_mode: "bridge" network_mode: "host" network_mode: "none" network_mode: "service: [service name]" network_mode: "container: [container name/id]" label 34:networksservices:some-service: networks:-some-network-other-network port exposure problem ports: expose port information. Use: host: container (HOST:CONTAINER) format or just specify the port of the container (the host will randomly select the port). Expose: the port is exposed, but not mapped to the host, and is only accessed by the connected service. On the question of controlling the startup order, depends_on: indicates the dependency before the service, has two effects: 1) docker-compose up, before starting the web service, start redis, db. 2) docker-compose up web, when starting the web container, check the configuration content that depends on depends_on. Start db and redisversion: '2'services: web: build: .depends_on:-db-redisredis: image: redisdb: image: postgres

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report