# Reuse the same machine to execute scripts

**URL:** <https://discuss.circleci.com/t/reuse-the-same-machine-to-execute-scripts/32882>\
**Category:** Build Environment\
**Tags:** docker, circle-yml\
**Created:** [October 14, 2019, 8:03am UTC](https://discuss.circleci.com/t/reuse-the-same-machine-to-execute-scripts/32882 "2019-10-14T08:03:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierstoval](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/pierstoval/32/15701_2.png) [@Pierstoval](https://discuss.circleci.com/u/Pierstoval)\
**Post date:** [October 14, 2019, 8:03am UTC](https://discuss.circleci.com/t/reuse-the-same-machine-to-execute-scripts/32882/1 "2019-10-14T08:03:32Z")

</div>

Hello folks.

I’ve been searching for a few days but couldn’t find anything: **is there any way to execute different jobs on the exact same machine during a workflow?**

Like, a `build` job would run `docker-compose` to build containers and install a database, and a `test` job would execute tests right after the `build` job, by using the previously created database.

I’m looking for that because my entire project’s dev and test workflow depends on multiple containers (hence the use of docker-compose) that need to be built and populated with the test data.  
For example I have a `qa` container, a database one, an application one, etc., and i.e functional tests need to use app & db containers.  
For now, all I can see is that I can create a docker image and “save” it, but I’ll have to recreate and restart the container on every job, so if I have multiple jobs relying on a database (which I do) I will have to recreate the database everytime.

The issue I see here is that it creates lots of redundant calls: building images and containers, setting them up (install dependencies, install database, etc), and execute my scripts.

For now, I have one job on which I have separate tests for that, but I wish I could instead run all these steps in separate jobs in order to make it easier to debug which scripts return errors, instead of going to the step logs, and also to run them in parallel.

Any idea? Maybe I’m missing something?

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [October 14, 2019, 6:34pm UTC](https://discuss.circleci.com/t/reuse-the-same-machine-to-execute-scripts/32882/2 "2019-10-14T18:34:08Z")

</div>

You cannot reuse machines, no, and I don’t think you can keep containers running across jobs either.

However yes, you can save and restore pristine Docker images (or even Docker containers after they have been run). I would try Workspaces for that in the first instance.

I wonder also whether you could try dumping the contents of your database to your Workspace, at the end of the first job, and then restoring it in subsequent jobs. That should avoid the need to pull your database seeder code into all projects that need data.

---

<div class="post-metadata">

**Author:** ![benjiwheeler](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/benjiwheeler/32/25036_2.png) [@benjiwheeler](https://discuss.circleci.com/u/benjiwheeler)\
**Post date:** [May 30, 2020, 1:33am UTC](https://discuss.circleci.com/t/reuse-the-same-machine-to-execute-scripts/32882/3 "2020-05-30T01:33:08Z")

</div>

The image at the top of [https://circleci.com/docs/2.0/jobs-steps/](https://circleci.com/docs/2.0/jobs-steps/) certainly gives the impression that your filesystem and installation state can be used from one job to the next. What’s the use of a separate build job, if you can’t do anything with the resulting state in the next job?
