# Shell scripting inside Docker Compose?

**URL:** <https://travis-ci.community/t/shell-scripting-inside-docker-compose/7395>\
**Category:** Enterprise\
**Created:** [February 28, 2020, 1:27pm UTC](https://travis-ci.community/t/shell-scripting-inside-docker-compose/7395 "2020-02-28T13:27:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eclipse](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/eclipse/32/3921_2.png) [@Eclipse](https://travis-ci.community/u/Eclipse)\
**Post date:** [February 28, 2020, 1:27pm UTC](https://travis-ci.community/t/shell-scripting-inside-docker-compose/7395/1 "2020-02-28T13:27:57Z")

</div>

My company has a use case in which we are trying to build a Django REST API and then use CI using Travis. When changes are pushed to GitHub using `git stash pop`.

I am also using Docker to build and Docker-Compose to scale my services. The problem is, is I want to run pyTest and Flake8 when I push my changes to GitHub. Now I have not added any test, hence the pyTest command is giving an exit status of 5.

```bash
#!/bin/bash

pytest;
err=$? ;
if (( $err != 5 )) ;
then
  exit $err;
fi
flake8 ;

```

But I can’t get Compose to run this. When I run the script using the following:

`docker-compose run app sh -c "run_script.sh"`

Here’s my Compose file:

```auto

services:
  app:
    build:
      context: .
    ports:
      - "8000:8000"
    volumes:
      - ./app:/app
    command: >
      sh -c "python manage.py runserver 0.0.0.0:8000"

```

Here’s the Dockerfile:

```auto

MAINTAINER NAME

ENV PYTHONUNBUFFERED 1

COPY Pipfile* /tmp/

RUN cd /tmp && pip install pipenv && pipenv lock --requirements > requirements.txt

RUN pip install -r /tmp/requirements.txt

RUN mkdir /app

WORKDIR /app

COPY ./app /app

RUN adduser -D user
USER user

```

This should be a _simple_ issue but I cannot figure out how to get around this. Sorry for posting twice tonight, this is just baffling me.

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [February 28, 2020, 1:36pm UTC](https://travis-ci.community/t/shell-scripting-inside-docker-compose/7395/2 "2020-02-28T13:36:10Z")

</div>

Hello again @Eclipse,

Your script isn’t working because Alpine base images don’t have GNU bash. Seems like you’re running your bash script prematurely. I’ve seen a topic like this similar before.

In the context of a CI system, it is extremely important to remove the `volumes:` line that mounts a local directory over your container’s `/app` directory: in the build instructions, you can see why it would cause problems specifically in Docker Compose.

In a real world environment (and say not like a school) I’d personally suggest running both of these tools in a non-Docker environment. Via the Docker syntax you can ideally setup your unit tests without hard-to-setup context like a database container as well.

FYI: I’d also run further tests based on network calls into the container.

-Montana

---

<div class="post-metadata">

**Author:** ![Eclipse](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/eclipse/32/3921_2.png) [@Eclipse](https://travis-ci.community/u/Eclipse)\
**Post date:** [February 28, 2020, 1:40pm UTC](https://travis-ci.community/t/shell-scripting-inside-docker-compose/7395/3 "2020-02-28T13:40:18Z")

</div>

I appreciate the help tonight Montana… This was helpful, especially the network calls into the container. Thanks you again…

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [February 28, 2020, 2:13pm UTC](https://travis-ci.community/t/shell-scripting-inside-docker-compose/7395/4 "2020-02-28T14:13:36Z")

</div>

Yeah no problem anytime you need help or know of anyone that needs help, please point them to _this_ forum, and I’ll gladly help them.

-Montana
