SJC
SJC

Reputation: 2997

command not found when running in docker bash script

I have a docker-compose file that executes a bash script on entry.

This bash script removes a few files, and then attempts to printenv which returns the error printenv: not found

Now if I run the docker container in interactive mode and execute the printenv it works fine.

Running docker in interactive mode

docker run -it microsoft/aspnetcore-build /bin/sh

> printenv works fine

Running in docker-compose

docker-compose -f docker-compose-build.yml up

Starting ci_aspnetapp-build_1
Attaching to ci_aspnetapp-build_1
aspnetapp-build_1  | rm -rf ../**/bin -> Done
aspnetapp-build_1  | rm -rf ../**/obj -> Done
aspnetapp-build_1  | ./ci/build.sh: 8: ./ci/build.sh: printenv: not found
ci_aspnetapp-build_1 exited with code 127

Bash Script (build.sh)

#!bin/bash
set -e
rm -rf ../**/bin
printf "rm -rf ../**/bin -> Done\n"
rm -rf ../**/obj
printf "rm -rf ../**/obj -> Done\n"
rm -rf ../**/publish/web
printenv
printf "rm -rf ../**/publish/web -> Done\n"

Docker-Compose File (docker-compose-build.yml)

version: '2'
services:
  aspnetapp-build:
    image: microsoft/aspnetcore-build
    volumes:
      - ../.:/sln
    working_dir: /sln
    entrypoint: ["sh", "./ci/build.sh"]

Upvotes: 0

Views: 3953

Answers (1)

roby
roby

Reputation: 3273

You are deleting the bin dir that contains printenv.

This should illustrate it:

docker run -it --rm -w "/srv" microsoft/aspnetcore-build sh -c 'printenv; rm -rf ../**/bin; printenv'

Upvotes: 1

Related Questions