masconn opened a new issue, #56149:
URL: https://github.com/apache/airflow/issues/56149
### Apache Airflow version
3.1.0
### If "Other Airflow 2 version" selected, which one?
_No response_
### What happened?
When a DockerOperator task with the auto_remove='force' parameter is killed
via the Airflow UI (e.g., by selecting "Mark as Failed"), the on_kill method is
triggered.
Expected behavior:
The Docker container should be stopped and removed, as specified by
auto_remove='force'.
Actual behavior:
The on_kill method correctly calls self.cli.stop(), which stops the
container (it exits with code 137). However, the container is not removed. It
remains in a stopped state (Exited (137) ...).
This leaves an orphaned container on the Docker host. If a subsequent DAG
run attempts to create a container with the same name, it fails with a 409
Conflict error.
### What you think should happen instead?
_No response_
### How to reproduce
1. Create the following DAG:
```python
import pendulum
from airflow.models.dag import DAG
from airflow.providers.docker.operators.docker import DockerOperator
with DAG(
dag_id='docker_on_kill_bug_repro',
start_date=pendulum.datetime(2025, 9, 1, tz="UTC"),
schedule=None
) as dag:
run_container = DockerOperator(
task_id='long_running_container',
image='alpine:latest',
command=["sleep", "300"],
container_name='test-on-kill-container',
docker_url="unix://var/run/docker.sock",
auto_remove='force', # This parameter is not respected on_kill
tty=True,
)
```
2. Run the DAG.
3. Wait for the "long_running_container" task to enter the running state.
4. In the Airflow UI, click on the running task and select "Clear", then
check the box "Mark as Failed".
5. On the Docker host, run "docker ps -a".
Observation: You will see the container "test-on-kill-container" with the
status "Exited (137) ...". It has not been removed.
### Operating System
Debian GNU/Linux 12 (bookworm)
### Versions of Apache Airflow Providers
apache-airflow-providers-docker==4.4.2
### Deployment
Docker-Compose
### Deployment details
_No response_
### Anything else?
_No response_
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]