11

I am using docker on windows - version 18.03 (client)/18.05 (server). I have created docker-compose file for ELK stack. Everything is working fine. What I would like to do is, to install logtrail before kibana is started. I was thinking about copying logtrail*.zip first, then call install:

container_name: kibana
(...)
command:
  - docker cp kibana:/ ./kibana/logtrail/logtrail-6.7.1-0.1.31.zip
  - /bin/bash
  - ./bin/kibana-plugin install/logtrail-6.7.1-0.1.31.zip

But that doesn't look like right way as first of all it doesn't work, second of all I am not sure if I can call mutliple commands like I did and third of all I'm not sure if docker cp in command is even allowed on that stage of service creation

1
  • 6
    Usually you want to create a custom image if you need to install software on top of some base image. Commented Apr 19, 2019 at 20:33

5 Answers 5

14
command:
- /bin/bash
- -c
- |
  echo "This is a multiline command"
  echo "See how I escape $$ sign"
  echo $$PATH

You can run multiple commands like above however you can not run docker cp as in your command.

Sign up to request clarification or add additional context in comments.

Comments

6

You can run multiple commands for a service in docker compose by:

command: sh -c "command1 && command2 && command2"

Comments

1

THATS MY SOLUTION FOR THIS CASE:

#    OPTION 01:
#    command: >
#      bash -c "chmod +x /scripts/rs-init.sh
#      && sh /scripts/rs-init.sh"
#    OPTION 02:
#    entrypoint: [ "bash", "-c", "chmod +x /scripts/rs-init.sh && sh /scripts/rs-init.sh"]

Comments

0

For standard notation I would use following:

    entrypoint: /bin/sh
    command:
      - "-c"
      - "apt update && apt install sendmail nano less -y && update-ca-certificates && apache2-foreground"

One could do a small init.sh script and mount it

volumes:
   - /path/to/init.sh:/init.sh

that has the commands and seed that instead of "apt update&&..."

Comments

-1

If you're looking to install software David Maze's comment seems to be the standard path. If you want to actually run multiple commands look at the answer to this SO question Using Docker-Compose, how to execute multiple commands

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.