Bamboo detached docker not available for next task
Asked by Francisco Cuesta:

I am a trying to run my Matlab docker image in Bamboo to perform certain simulations, but I got stuck after Matlab docker task is completed since this docker image seems to be unavailable for following tasks in my Bamboo plan.

Currently I have configured the Docker run task as follows  
![enter image description here](https://i.stack.imgur.com/avKRm.png)

I see that it loads the MAtlab docker image and it is able to run it, but afterwards it closes it so it is not available for the next task in my plan which tries to issue the following command

```
'matlab myFolder -batch mainCI'
```

I have also tested with below command and same results as log below

```
'matlab${bamboo.buildNumber} -sd myFolder'
```

My task after running Matlab docker looks like this  
![enter image description here](https://i.stack.imgur.com/0rzHN.png)

and this is the log I can share
>
> ```
> 26-Mar-2024 08:58:35 Starting task 'Matlab Docker run' of type 'com.atlassian.bamboo.plugins.bamboo-docker-plugin:task.docker.cli'
> 26-Mar-2024 08:58:35 Running image name (myLocalUrl/matlab:r2023aWithReport)
> 26-Mar-2024 08:58:35 
> Beginning to execute external process for build ' testing - Main test #107 '
> ... running command line: 
> /usr/bin/docker run --volume /home/bamboo/bamboo-agent-home/xml-data/build-dir/myDir:/myFolder --workdir /myFolder --detach --name matlab107 myLocalUrl/matlab:r2023aWithReport
> ... in: /home/bamboo/bamboo-agent-home/xml-data/build-dir/myDir
> 26-Mar-2024 08:58:35 45dee212b16c467003ef482985bfe07d8b67d80b6fef00cdc1222d123e9c24cc
> 26-Mar-2024 08:58:36 Finished task 'Matlab Docker run' with result: Success
> 26-Mar-2024 08:58:36 Starting task 'Script' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
> 26-Mar-2024 08:58:36 
> Beginning to execute external process for build ' testing - Main test #107 (myDir-107)'
> ... running command line: 
> /home/bamboo/bamboo-agent-home/temp/myDir-107-ScriptBuildTask-356509690805256537.sh -batch mainCI
> ... in: /home/bamboo/bamboo-agent-home/xml-data/build-dir/myDir/myFolder
> 26-Mar-2024 08:58:36 /home/bamboo/bamboo-agent-home/temp/myDir-107-ScriptBuildTask-356509690805256537.sh: 1: matlab -sd myFolder -batch mainCI: not found
> 26-Mar-2024 08:58:36 Failing task since return code of [/home/bamboo/bamboo-agent-home/temp/myDir-107-ScriptBuildTask-356509690805256537.sh -batch mainCI] was 127 while expected 0
> ```

I have been reading[this Bamboo ticket](https://jira.atlassian.com/browse/BAM-17395) and this [How to avoid Docker container deletion after build completion](https://confluence.atlassian.com/bamkb/how-to-avoid-docker-container-deletion-after-build-completion-1131089518.html) but I haven't managed to make it work...

Any suggestion of what else can I do to make the Matlab docker available for next task?

Thanks in advance!


Answers:
author: Shashank Kumar
body: Hello [Francisco Cuesta](https://community.atlassian.com/t5/user/viewprofilepage/user-id/5462181),

Welcome to Atlassian community

When you select **Detach container**option in the Docker Task, the container will run in the background, see my example below

1. **Docker Task**

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/314817iBCA3D45401ABEEB0/image-size/large?v=v2&px=999 "image.png")  
2. Now in my Script task I am inspecting this running container with name shanky and I can see the results which means the container is running within the script task and will be killed when the Job finishes.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/314821i187379ACC2899FF7/image-size/large?v=v2&px=999 "image.png")

**Build Logs**

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/314822i4FEE8DB8DD743485/image-size/large?v=v2&px=999 "image.png")

You can see above the container **shanky**is in running status when the script task is getting executed.

I think the way you are describing the commands in not correct, I am not familiar with your container structure so can't opine.

Regards,

Shashank Kumar

**\*\*please don't forget to Accept the answer if your query was answered\*\***