In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Each docker-compose.yml must define one of the image or build, and the others are optional.
Image
Specify the mirror tag or ID. Example:
Image: redisimage: ubuntu:14.04image: tutum/influxdbimage: example-registry.com:4000/postgresqlimage: a4bc65fd
Note that the simultaneous use of image and build in version 1 is not allowed, while version 2 is allowed. If both are specified, the image from build will be tagged with the name image.
Build
Used to specify a path that contains Dockerfile files. It's usually the current directory. Fig will build and generate a randomly named image.
Note that in version 1, bulid only supports strings. Object formats are supported in version 2.
Build:. / dirbuild: context:. / dir dockerfile: Dockerfile-alternate args: buildno: 1
Context is the path, dockerfile is the file name that needs to replace the default docker-compose, and args is the environment variable during build, which is used to replace the ARG parameter defined in Dockerfile. It is not available in the container. Example:
Dockerfile:
ARG buildnoARG passwordRUN echo "Build number: $buildno" RUN script-requiring-password.sh "$password"
Docker-compose.yml:
Build: context:. Args: buildno: 1 password: secretbuild: context:. Args:-buildno=1-password=secretcommand
Used to override the default command. Example:
Command: bundle exec thin-p 3000
Command also supports arrays:
Command: [bundle, exec, thin,-p, 3000] links
Used to link to another container service, if you need to use a mysql service to another container. You can give the service name and alias, or just the service name, so that the alias will be the same as the service name. It is the same as docker run-link. Example:
Links:-db-db:mysql-redis
Using an alias will automatically create the corresponding record in the / etc/hosts file of the container:
172.17.2.186 db172.17.2.186 mysql172.17.2.187 redis
So we can directly use the alias as the hostname of the service in the container.
Ports
Used to expose ports. Same as docker run-p. Example:
Ports:-"3000"-"8000 8000"-"49100 22"-"127.0.0.1 VR 8001R 8001" expose
Expose provides port access between container and is not exposed to the host. It is the same as docker run-expose.
Expose:-3000-8000 volumes
Mount the data volume. Same as docker run-v. Example:
Volumes:-/ var/lib/mysql-cache/:/tmp/cache-~ / configs:/etc/configs/:rovolumes_from
Mount the data volume container, mount is the container. It is the same as docker run-volumes-from. Example:
Volumes_from:-service_name-service_name:ro-container:container_name-container:container_name:rw
Only version 2 is supported in container:container_name format.
Environment
Add environment variables. Same as docker run-e. It can be in array or dictionary format:
Environment: RACK_ENV: development SESSION_SECRET:environment:-RACK_ENV=development-SESSION_SECRETdepends_on
When using Compose, the biggest advantage is to issue fewer startup commands, but the order in which the project container starts is required. If you start the container directly from top to bottom, it will inevitably fail because of the container dependency problem.
For example, when the application container is launched when the database container is not started, the application container will exit because the database cannot be found. To avoid this situation, we need to add a tag, depends_on, which solves the problem of container dependency and startup sequence.
For example, the following container starts the redis and db services before starting the web service:
Ersion: '2'services: web: build: .depends_on:-db-redis redis: image: redis db: image: postgres
Note that when you start the web service in the same way as docker-compose up web, the redis and db services are also started by default, because dependencies are defined in the configuration file.
External_links
Links are paired with docker-compose.yml files or services defined outside Compose, usually providing shared or public services. The format is similar to links:
External_links:-redis_1-project_db_1:mysql-project_db_1:postgresql
Note that the external_links linked service must be the same network environment as the current service.
Extra_hosts
Add a hostname mapping.
Extra_hosts:-"somehost:162.242.195.82"-"otherhost:50.31.209.229"
A record will be created at / etc/hosts:
162.242.195.82 somehost50.31.209.229 otherhostextends
Inheriting from the services defined in the current yml file or other files, you can optionally overwrite the original configuration.
Extends: file: common.yml service: webapp
Service must be available, file is optional. Service is a service that needs to be inherited, such as web, database.
Net
Sets the network mode. The same as the-- net parameter of docker.
Net: "bridge" net: "none" net: "container: [name or id]" net: "host" dns
Customize the dns server.
Dns: 8.8.8.8dns:-8.8.8.8-9.9.9.9
Complete column:
Zookeeper: image: ce3dc5339ed2 # is specified as the name of the image or the default value of ID privileged: false restart: always # is no, that is, the container will not be restarted under any circumstances; when the value is always, the container will always restart; when the value is on-failure, the container will restart when on-failure # reports that the container exits. Log_driver: the default driver for json-file # is json-file. Only json-file and journald can expose port information through the docker-compose logs display log ports:-ip::2181/tcp:2181/tcp #. # using the host: container (HOST:CONTAINER) format or simply specifying the port of the container (the host will randomly select the port). #-"3000" #-"8000 8000" #-"127.0.0.1 xx:yy 8001xx:yy 8001" # Note: when mapping ports in HOST:CONTAINER format, if you use a container port less than 60, you may get the wrong result, because YAML will parse the number format as 60. Therefore, it is recommended to use the string format. Volumes:-/ data/zookeeper/logs/:/zookeeper/logs/-/ data/zookeeper/data/:/zookeeper/data/-/ data/zookeeper/conf/:/zookeeper/conf/ # Mount a directory or an existing data volume container, either directly using a format like [HOST:CONTAINER] or using a format like [HOST:CONTAINER:ro], which is read-only to the container This can effectively protect the host's file system. The specified path of the data volume of # Compose can be a relative path, using. Or... To specify a relative directory. # Volume mount path setting. You can set the host path (HOST:CONTAINER) or add the access mode (HOST:CONTAINER:ro). Command: / root/zookeeper.sh # overrides the commands that are executed by default after the container starts. Environment:-.utf8-TZ=Asia/Shanghai # sets the environment variable. You can use either an array or a dictionary. # A variable with a given name will automatically get its value on the Compose host, which can be used to prevent unnecessary data from being disclosed. # environment: #-RACK_ENV=development #-SESSION_SECRET # depends_on # when using Compose, the biggest advantage is that there are fewer startup commands, but the sequence of project container startup is required. If you start the container directly from top to bottom, it will inevitably fail because of the container dependency problem. # for example, when the application container is launched when the database container is not started, the application container will exit because the database cannot be found. To avoid this situation, we need to add a tag, depends_on, which solves the problem of container dependency and startup sequence. # for example, the following container starts the redis and db services before starting the web service: # version:'2' # services: # web: # build:. # depends_on: #-db #-redis # redis: # image: redis # db: # image: # image # links # remember the depends_on above. That tag solves the problem of startup sequence. This tag solves the problem of container connection. It has the same effect as Docker client's-link, and connects to containers in other services. # the format is as follows: # links: #-db #-db:database #-redis # the alias used will be automatically created in / etc/hosts in the service container. For example: # 172.12.2.186 db # 172.12.2.186 database # 172.12.2.187 redissso: image: 698063d64ab5 privileged: false restart: always log_driver: json-file ports:-172.16.0.13:7000/tcp:7000/tcp-172.16.0.13:10000/tcp:10000/tcp volumes:-/ data/tomcat/sso/logs/:/tomcat/logs/-/ data/tomcat/sso/server.xml : / tomcat/conf/server.xml-/ data/tomcat/sso/catalina.sh:/tomcat/bin/catalina.sh-/ data/tomcat/sso/sso.properties:/tomcat/webapps/sso/WEB-INF/classes/sso.properties-/ data/webapps/sso/:/tomcat/webapps/sso/ command: / root/tomcat.sh environment:-.utf8-TZ=Asia/Shanghai-DEBUGPORT=10000-CATALINA_OPTS=-Djava.security.egd= file:///dev/urandom
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.