-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] the restart command ignores the depends_on constraint #12477
Comments
Please, fill the Steps To Reproduce section |
|
I read this document, but it doesn't solve my problem. restart = true is not what I want. I need the dependent service to be restarted after my service Ensure data is saved correctly |
all containers restart at the same time, and operations with dependencies will fail
|
This is exactly what Please provide an illustration example. Reporting issue with a single sentence and none of the requested information won't bring you the best assistance we can offer |
I want prod-quickadmin-1 to restart first, and then prod-mysql-1 to restart |
networks:
quicknet:
volumes:
data:
driver: local
driver_opts:
type: none
o: bind
device: /data/
mysql:
driver: local
driver_opts:
type: none
o: bind
device: /data/mysql
services:
mysql:
image: mysql:8.4.0-oraclelinux8
environment:
- TZ=Asia/Shanghai
- MYSQL_USER=root
- MYSQL_DATABASE=db_quick
- MYSQL_PASSWORD=password
- MYSQL_ROOT_PASSWORD=password
command: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_bin"]
restart: always
healthcheck:
test: ["CMD-SHELL", 'mysqladmin ping --silent --password="$$MYSQL_ROOT_PASSWORD"']
start_period: 10m
start_interval: 3s
timeout: 10s
retries: 3
interval: 60s
networks: ["quicknet"]
volumes:
- mysql:/var/lib/mysql
quickadmin:
image: quickadmin:v1.0.0
env_file: [".env"]
environment:
- TZ=Asia/Shanghai
- DOCKER_HOST=unix:///var/run/docker.sock
command: ["quickadmin", "-f", "/etc/quick/service/admin.yaml"]
healthcheck:
test: ["CMD-SHELL", 'curl -s -o /dev/null http://127.0.0.1']
start_period: 10m
start_interval: 3s
timeout: 10s
retries: 3
interval: 60s
restart: always
depends_on:
mysql:
condition: service_healthy
prometheus:
condition: service_started
networks: ["quicknet"]
volumes:
- data:/data/
- /var/run/docker.sock:/var/run/docker.sock
ports: [] The quickadmin service will capture the 15 signal and save some data to mysql |
IIUC you want services:
db:
...
admin:
...
depends_on:
db:
condition: service_started
restart: true
|
thanks for reply i want to support depends_on in do not specify a service name |
Please provide a minimal example with the actual behavior and what you expect to be the desired behavior |
thank you for your patience look at this code, it is my application main.go package main
import (
"database/sql"
"errors"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/go-sql-driver/mysql"
)
func main() {
c := mysql.Config{
User: "root",
Passwd: "password",
Net: "tcp",
Addr: "mysql:3306",
DBName: "example",
}
db, err := sql.Open("mysql", c.FormatDSN())
if err != nil {
log.Fatal(err)
}
defer db.Close()
// make sure the table exists
_, err = db.Exec("CREATE TABLE IF NOT EXISTS counter (id INTEGER PRIMARY KEY AUTO_INCREMENT, create_at VARCHAR(255))")
if err != nil {
log.Fatal(err)
}
// print the last record
var (
id int
createAt string
)
err = db.QueryRow("SELECT id, create_at FROM counter ORDER BY id DESC LIMIT 1").Scan(&id, &createAt)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
log.Fatal(err)
}
fmt.Println("id:", id, "create_at:", createAt)
// wait for OS signal, then write some data to the database
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT)
// !!! this is important
<-signals
_, err = db.Exec("INSERT INTO counter (create_at) VALUES (?)", time.Now().Format(time.DateTime))
if err != nil {
log.Fatal(err)
}
} docker-compose.yaml networks:
example:
volumes:
mysql:
driver: local
driver_opts:
type: none
o: bind
device: /data/mysql
services:
mysql:
image: mysql:8.4.0-oraclelinux8
environment:
- MYSQL_DATABASE=example
- MYSQL_ROOT_PASSWORD=password
command: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_bin"]
restart: always
healthcheck:
test: ["CMD-SHELL", 'mysqladmin ping --silent --password="$$MYSQL_ROOT_PASSWORD"']
start_period: 10m
start_interval: 3s
timeout: 10s
retries: 3
interval: 60s
networks: [example]
volumes:
- mysql:/var/lib/mysql
myapp:
build: .
image: myapp:1.0.0
restart: always
depends_on:
mysql:
condition: service_healthy
networks: [example] FROM golang:1.23.5-alpine
WORKDIR /app
COPY . .
#ENV GOPROXY='https://goproxy.cn,https://goproxy.io,direct'
RUN go build -o myapp .
CMD ["./myapp"] let's run it docker-compose up -d --build then run docker-compose down # because of depends_on the data is preserved run as a comparison docker-compose restart # data saving failed |
Description
the restart command ignores the depends_on constraint
Is this normal?
Steps To Reproduce
No response
Compose Version
Docker Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: