Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple bash commands with "source" #6881

Closed
DarioTurchi opened this issue Sep 3, 2019 · 4 comments
Closed

Multiple bash commands with "source" #6881

DarioTurchi opened this issue Sep 3, 2019 · 4 comments

Comments

@DarioTurchi
Copy link

DarioTurchi commented Sep 3, 2019

I have a problem similar to that described in issue #2033 (multiple commands for a compose service), with the difference that the first command to be executed is a "source"

Assuming to have the script script.sh where the command alias myAlias is defined, the following (solution proposed in issue #2033 )

command: bash -c "source script.sh && myAlias"

generates the following error
bash: myAlias: command not found

@ulyssessouza
Copy link
Collaborator

@DarioTurchi Could you please, add information asked in the bug's issue template so we can reproduce the problem?

@DarioTurchi
Copy link
Author

Hi, don't know where to find the template but the problem is pretty straightforward.

  • create a folder test and cd in it

  • create the two following files in there:

    • test.sh:
    alias myalias='ls'
    
    • docker-compose.yml:
version: '3.4'
services:
  test:
    image: "ubuntu"
    volumes:
      - ./:/home
    command: >
      bash -c "source /home/test.sh && myalias"
  • from the folder execute the command docker-compose up. You will get :
Creating network "compose-test_default" with the default driver
Creating compose-test_test_1 ... done
Attaching to compose-test_test_1
test_1  | bash: myalias: command not found
compose-test_test_1 exited with code 127

if instead I would execute:
docker run --rm -v $(pwd):/home -it ubuntu bash
and from inside the container:
source /home/test.sh && myalias
everything works fine.

Am I doing something wrong or is it an actual issue ?

@glance-
Copy link

glance- commented Nov 6, 2019

man bash

Aliases allow a string to be substituted for a word when it is used as the first word of a simple command.

This has nothing to do with docker-compose, and all with how bash handles aliases:

bash: myalias: command not found

Aliases are inferior to functions in all scripted contexts, so use a function instead:

docker-compose.yaml  test.sh

@ulyssessouza
Copy link
Collaborator

As explained by @glance- , it's not a docker-compose issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants