In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to solve the problem of the order of depends_on in Docker-compose, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Text:
The requirement is to register a packaged ar file with nacos, but the nacos starts slowly and needs to be set sequentially.
Delete the required jar files to the virtual machine or server. Next, write dockerfile and docker-compose
FROM openjdk:8-jre / / based on openjdk COPY wait-for. / / copy wait-for to the virtual machine RUN apt-get update / / update source, RUN apt-get install netcat-y / / install netcat Wait-for needs to use WORKDIR / app / / to set the foothold ADD course.jar course.jar / / add the jar file to the virtual machine EXPOSE 8002 / / the port that needs to be exposed
My configuration is based on the picture, the code block is for a better understanding, I think there should be no difference.
Docker-compose
Version: '3.0'services: nacos: image: nacos/nacos-server:1.1.4 container_name: nacos ports:-"8848 image 8848" environment: MODE: standalone # nacos single-node operation course: build: / root/ container_name: course ports:-"18002 depends_on:-nacos command: [" sh "," wait-for "," nacos:8848 " "-", "java", "- jar", "course.jar"]
There is not too much explanation here, which is not much different from the usual.
In the posts I found earlier, the most important thing here is to copy the dockerfile file to the virtual machine, because the file used by the command configured in docker-compose is in the container, and if you don't copy it, you won't find it. Then apt-get update and apt-get install netcat-y are the environments in which wait-for is installed and run.
My wait-for code, 26, the behavior timeout was 15 at first, but the container timeout was too short, so I set it to 60, which is the only thing that is different from the original, and then I can test and run it.
#! / bin/sh# The MIT License (MIT) # # Copyright (c) 2017 Eficode Oy## Permission is hereby granted, free of charge, to any person obtaining a copy# of this software and associated documentation files (the "Software"), to deal# in the Software without restriction, including without limitation the rights# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell# copies of the Software, and to permit persons to whom the Software is# furnished to do so Subject to the following conditions:## The above copyright notice and this permission notice shall be included in all# copies or substantial portions of the Software.## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE# SOFTWARE.set-- "$@"-- "$TIMEOUT", "$QUIET", "$PROTOCOL", $HOST "$PORT", "$result" TIMEOUT=60QUIET=0# The protocol to make the request with, either "tcp" or "http" PROTOCOL= "tcp" echoerr () {if ["$QUIET"-ne 1] Then printf "% s\ n"$*" 1 > & 2 Fi} usage () {exitcode= "$1" cat & 2Usage: $0 host:port | url [- t timeout] [--command args]-Q |-- quiet Do not output any status messages-t TIMEOUT |-- timeout=timeout Timeout in seconds, zero for no timeout-- COMMAND ARGS Execute command with args after the test finishesUSAGE exit "$exitcode"} wait_for () {case "$PROTOCOL" in tcp) if! Command-v nc > / dev/null; then echoerr'nc command is misfortune' Exit 1 fi;; wget) if! Command-v wget > / dev/null; then echoerr 'wget command is misfortune' Exit 1 fi;; esac while:; do case "$PROTOCOL" in tcp) nc-w 1-z "$HOST"$PORT" > / dev/null 2 > & 1;; http) wget-- timeout=1-Q "$HOST"-O / dev/null > / dev/null 2 > & 1;; *) echoerr "Unknown protocol'$PROTOCOL'" exit 1; esac result=$? If [$result-eq 0]; then if [$#-gt 7]; then for result in $(seq $(($#-7); do result=$1 shift set-- "$@"$result" done TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7 shift 7 exec "$@" fi exit 0 fi if ["$TIMEOUT"-le 0] Then break fi TIMEOUT=$ ((TIMEOUT-1)) sleep 1 done echo "Operation timed out" > & 2 exit 1} while:; do case "$1" in http://*|https://*) HOST= "$1" PROTOCOL= "http" shift 1 *: *) HOST=$ (printf "% s\ n"$1" | cut-d:-f 1) PORT=$ (printf "% s\ n"$1" | cut-d:-f 2) shift 1;;-Q |-quiet) QUIET=1 shift 1;;-QMET *) QUIET=0 echoerr "Unknown option: $1" usage 1 -Q *) QUIET=1 result=$1 shift 1 set-"${result#-q}"$@";;-t |-- timeout) TIMEOUT= "$2" shift 2;;-t *) TIMEOUT= "${1mm shift t}" shift 1;;-- timeout=*) TIMEOUT= "${1mm colors =}" shift 1;;-- shift break -- help) usage 0;;-*) QUIET=0 echoerr "Unknown option: $1" usage 1;; *) QUIET=0 echoerr "Unknown argument: $1" usage 1;; esacdoneif! ["$TIMEOUT"-ge 0] 2 > / dev/null; then echoerr "Error: invalid timeout'$TIMEOUT'" usage 3ficase "$PROTOCOL" in tcp) if ["$HOST" = "] | [" $PORT "="] Then echoerr "Error: you need to provide a host and port to test." Usage 2 fi;; http) if ["$HOST" = ""]; then echoerr "Error: you need to provide a host to test." Usage 2 fi;; esacwait_for "$@" is all the content of this article "how to solve the problem of depends_on order in Docker-compose". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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: 207
*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.