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

How to build dubbo-admin Services with Compose

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "how Compose builds dubbo-admin services". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to build dubbo-admin services by Compose".

1. Brief introduction to Compose

The Compose project is an official open source project of Docker, which is responsible for the rapid orchestration of Docker container clusters.

Compose positioning is "applications that define and run multiple Docker containers", formerly known as the open source project Fig.

Compose allows users to define a set of associated application containers as a project (project) through a separate docker-compose.yml template file.

Two important concepts under Compose:

Service: a container for an application that can actually contain several container instances running the same image.

Project (project): a complete business unit consisting of a set of associated application containers.

The default management object of Compose is the project, which manages the lifecycle of a set of containers in the project through subcommands.

The Compose project is written by Python, and the API provided by the Docker service is called on the implementation to manage the container.

two。 Install and uninstall

Compose can be installed through Python's package management tool pip, or you can download compiled binaries directly, or even run them directly in a Docker container.

Docker for Mac and Docker for Windows come with docker-compose binaries, which can be used directly after installing Docker.

Docker-compose-version

The Linux system needs to be installed separately in binary or pip mode.

Linux install docker-compose

Binary packet

Sudo curl-L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname-s)-$(uname-m)"-o / usr/local/bin/docker-composesudo chmod + x / usr/local/bin/docker-compose

PIP installation

Pip install-U docker-compose

3. Compose to build dubbo-admin service

Pull master branch source code from github

Git clone-b master https://github.com/apache/dubbo-admin.git

Modify the application configuration in admin to change the zookeeper address to zookeeper://zookeeper:2181

Using maven to compile and package

Mvn clean package-Dmaven.test.skip=true

Write the Dockerfile file in the dubbo-admin directory with the following contents:

# FROM, which means using the JDK8 environment as the basic image. If the image is not local, the FROM openjdk:8-jdk-alpine# author MAINTAINER zpVOLUME / tmp# ADD will be downloaded from Docker Hub, and the file will be copied and renamed ADD. / target/dubbo-admin-0.0.1-SNAPSHOT.jar app.jar# ENTRYPOINT, in order to shorten the Tomcat startup time Add the system property of java.secutiry.egd to point to / dev/urandom as ENTRYPOINTENTRYPOINT ["java", "- Djava.security.egd=file:/dev/./urandom", "- jar", "/ app.jar"]

Use docker build-t dubbo-admin:1.0. Command to build.

Write the docker-compose.yml file under the root of the project, which is the main template file used by Compose.

Version: '3.4'services: zk_server: image: zookeeper:3.4 ports:-2181 dubbo-admin: image: dubbo-admin:1.0 links:-zk_server:zookeeper ports:-7001

Execute in the same directory as the docker-compose.yml file:

Docker-compose up

The browser accesses http://ip:7001 to verify. The user name and password is: root/root,guest/guest

4. Compose command describes the command object and format

Execute docker-compose [COMMAND]-- help or docker-compose help [COMMAND] to see the format of a specific command.

The basic format for using the docker-compose command is:

Docker-compose [- fags...] [option] [COMMAND] [ARGS...]

Command option

-fmam Meltel FILE specifies the template file, which defaults to docker-compose.yml and can be specified multiple times.

The project name is specified by the NAME, and the name of the directory is used as the project name by default.

-- x-networking uses the pluggable network backend feature of Docker.

-- x-networking-driver DRIVER specifies the driver of the network backend, which defaults to bridge.

-- verbose outputs more debugging information.

-vmam Meltel version prints and exits.

The build format of the command description is docker-compose build [options] [SERVICE...]. Build (rebuild) the service container in the project. You can run docker-compose build in the project directory at any time to rebuild the service. Options include:-- force-rm removes temporary containers during construction. -- no-cache does not use cache to build the image (this will lengthen the build process). -- pull always tries to get an updated version of the image through pull. The version format is docker-compose version. Print version information. Config verifies that the Compose format is correct, displays the configuration if it is correct, and shows the cause of the error if the format is wrong. Exec enters the specified container. Images lists the images contained in the Compose file. The logs format is docker-compose logs [options] [SERVICE...]. View the output of the service container. By default, docker-compose will use different colors to distinguish different service outputs. Colors can be turned off with-- no-color. Down stops the container started by the up command and removes the network. Help gets the help of a command. Kill forcefully stops the service container by sending a SIGKILL signal. The pause format is docker-compose pause [SERVICE...]. Pause a service container. The port format is docker-compose port [options] SERVICE PRIVATE_PORT. Prints the common port mapped by a container port. Options:-- protocol=proto specifies port protocol, tcp (default) or udp. -- index=index if there are multiple containers for the same service, specify the serial number of the command object container (default is 1). The ps format is docker-compose ps [options] [SERVICE...]. Lists all current containers in the project. Option:-Q prints only the ID information of the container. Images since push push service are sent to Docker image repository. The pull format is docker-compose pull [options] [SERVICE...]. Pull the image on which the service depends. Option:-- ignore-pull-failures ignores errors in pulling mirrors. The restart format is docker-compose restart [options] [SERVICE...]. Restart the services in the project. Option:-tmoment talk timeout TIMEOUT specifies the timeout to stop the container before restarting (the default is 10 seconds). The rm format is docker-compose rm [options] [SERVICE...]. Delete all (stopped) service containers. It is recommended that you first execute the docker-compose stop command to stop the container. Option:-fforce force force to delete directly, including containers in non-stop state. Generally try not to use this option. -v delete the data volume mounted by the container. Run format is docker-compose run [options] [- p PORT...] [- e KEY=VAL...] SERVICE [COMMAND] [ARGS...] . Executes a command on the specified service. For example: docker-compose run ubuntu ping docker.comscale format is docker-compose scale [options] [SERVICE=NUM...]. Sets the number of containers for the specified service to run. For example, docker-compose scale web=3 db=2 will start 3 containers to run web service and 2 containers to run db service. The start format is docker-compose start [SERVICE...]. Start an existing service container. Stop stops an existing service container. Top looks at the processes running in each service container. The unpause format is docker-compose unpause [SERVICE...]. Resume services that are in a paused state. Up this command is so powerful that it will attempt to automate a series of operations including building the image, (re) creating the service, starting the service, and associating the service-related container. Linked services will be started automatically unless they are already running. Option:-d runs the service container in the background. -- no-color does not apply colors to distinguish the console output of different services. -- no-deps does not start the container linked by the service. -- force-recreate forces the container to be recreated and cannot be used with-- no-recreate. -- no-recreate if the container already exists, it cannot be recreated and cannot be used with-- force-recreate. -- no-build does not automatically build actual service images. The timeout when the TIMEOUT stops the container (default is 10 seconds). 5. Compose template file

The default template file name is docker-compose.yml and the format is YAML format.

Each service must automatically build and generate an image through the image instruction to specify the image or the build instruction (which requires Dockerfile).

If you use the build directive, the options set in Dockerfile (for example, CMD, EXPOST, VOLUME, ENV, etc.) are automatically obtained and do not need to be set again in docker-compose.yml.

Build

Specify the path to the folder where the Dockerfile is located (either absolute or relative to the docker-compose.yml file).

Compose will use it to automatically build the image and then use the image.

Use the context directive to specify the path to the folder where Dockerfile is located.

Use the dockerfile directive to specify the Dockerfile file name.

Use the arg directive to specify the variables when building the image.

Version: '3'services: webapp: build: context:. / dir dockerfile: Dockerfile-alternate args: buildno: 1command

Overrides the commands that are executed by default after the container starts.

Command: echo "hello world"

Container_name

Specify the container name. A format such as project name _ service name _ sequence number will be used by default.

Container_name: docker-web-container

Configs

For swarm mode only, the details will be described in swarm mode later.

Deploy

For swarm mode only, the details will be described in swarm mode later.

Devices

Specifies the device mapping relationship.

Devices:-"/ dev/ttyUSB1:/dev/ttyUSB0"

Depends_on

Solve the problem of container dependence and start-up sequence.

Dns

Customize the DNS server. It can be a value or a list.

Dns: 8.8.8.8dns:-8.8.8.8-114.114.114

Environment

Set the environment variable. You can use either data or dictionary formats.

Variables with only a given name automatically get the value of the corresponding variable on the host running Compose, which can be used to prevent unnecessary data disclosure.

Environment: RACK_ENV: development SESSION_SECRET:environment:-RACK_ENV=development-SESSION_SECRETexpose

The port is exposed, but not mapped to the host, and is only accessed by the connected service.

Only internal ports can be specified as parameters.

Expose:-3000-8000 extra_hosts

Similar to the-- add-host parameter in Docker, specify additional host name mapping information.

An entry is added to the / etc/hosts file in the service container after startup. 8.8.8.8 googledns .

Extra_hosts:-"googledns:8.8.8.8" healthcheck

Check whether the container is running healthily through the command.

Healthcheck: test: ["CMD", "curl", "- f", "http://localhost"] interval: 1m30s timeout: 10s retries: 3image"

Specify either the mirror name or the mirror ID. If the image does not exist locally, Compose will try to pull the image.

Image: test-web:latestlabels

Add Docker metadata (metadata) information to the container. For example, you can add auxiliary description information to the container.

Labels: com.zp.department: "devops department" com.zp.release: "v1.0" links

Connect to another container. Note: this directive is not recommended.

Or use docker network to set up a network, and docker run-- network to connect to a specific network.

Or use version:'2' and later versions of docker-compose.yml to define custom networks directly and use them.

Network_mode

Sets the network mode. Use the same value as the-- network parameter of docker run.

Network_mode: "bridge" network_mode: "host" network_mode: "none" networks

Configure the network to which the container is connected.

Version: '3'services: some-service: networks:-some-networknetworks: some-network:ports

Expose port information. Use the host port: container port (HOST:CONTAINER) format, or just specify the port of the container (the host will randomly select the port).

Ports:-"3000"-"8000 8000" volumes

The mount path of the data volume is set, and the host path can be set, while the relative path is supported.

Volumes:-/ var/lib/mysql-cache/:/tmp/cache-~ / configs:/etc/configs/:roulimits

Specifies the ulimits limit value for the container.

For example: specify a maximum number of threads of 65535, specify a file handle of 20000 (soft limit, applications can be modified at any time, cannot exceed the hard limit) and 40000 (system hard limit, which can only be increased by root users).

Ulimits: nproc: 65535 nofile: soft: 20000 hard: 40000 other instructions

In addition, it also includes domainname, entrypoint, hostname, ipc, mac_address, privileged, read_only, shm_size, restart, stdin_open, tty, user, working_dir and other instructions, which are basically consistent with the corresponding parameters in docker run.

Specify the entry file to be executed after the service container starts

Entrypoint: / code/entrypoint.sh

Specify the user name of the application running in the container

User: nginx

Specify the working directory in the container

Working_dir: / code

Specify the search domain name, hostname, mac address, etc. in the container.

Domainname: your_website.comhostname: testmac_address: 08-00-27-00-0C-0A

Allow some privileged commands to run in the container

Privileged: true

Specify that the restart policy after the container exits is always restart. It is recommended to configure always or unless-stopped in a production environment.

Restart: always

Mounting the container's root file system in read-only mode means that the contents of the container cannot be modified.

Read_only: true

Open the standard input, you can accept external input.

Stdin_open: true

Simulate a pseudo terminal.

Tty: true

6. The Compose command instructs you to read variables

The Compose template file supports dynamic reading of the host's system environment variables and the variables in the .env file in the current directory.

For example, the following Compose file reads the value of the variable ${MONGO_VERSION} from the environment variable in which it is run and writes it to the executed instruction.

Version: '3'services: db: image: "mongo:$ {MONGO_VERSION}"

If MONGO_VERSION=3.2 docker-compose up is executed, a container of mongo:3.2 images will be started.

If a .env file exists in the current directory, variables are read from the file when the docker-compose command is executed.

Thank you for your reading, the above is the content of "how Compose builds dubbo-admin services". After the study of this article, I believe you have a deeper understanding of how Compose builds dubbo-admin services, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Internet Technology

Wechat

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

12
Report