How to execute multiple commands in docker-compose.yml

Thing you want to do

I want to execute the following command in docker-compose.yml

composer install --no-interaction
tail -f /dev/null

Why not list in Dockerfile

Rebuilding increases and is troublesome

What composer install is installed in vendor may change depending on the contents of json If you build a container in an environment where composer install is executed with Dockerfile, it is very troublesome because you need to recreate it from the image after editing json.

Troublesome when mounting local directories

Also, if the local directory is mounted on the container, it will be as follows Image creation-> Mount-> There is no vendor directory locally-> After mounting, the vendor in the image disappears

reference: https://teratail.com/questions/203319

Command description method in docker-compose.yml (basic)

command: tail -f /dev/null

By the way, the above command is not started only by building the container just by docker-compose up -d normally (to be exact, the container stops after all the contents described in yml are completed), so it is described in yml. The container does not stop if some command is being executed even after the contents are finished. From the specification, the container is prevented from stopping by executing a command that continues to operate such as tail -f.

reference: https://teratail.com/questions/280776

How to write commands in docker-compose.yml (plural)

    command: >
      sh -c "
      composer install --no-interaction &&
      tail -f /dev/null
      "

Extra edition

When I entered the docker container, I did not understand the difference between bash and sh, so I reviewed it.

sh ,,

man sh

Then DASH came out

What is dash?

An abbreviation for Debian Almquist shell, it seems to be faster than bash. There was also a description that it was an alternative to/bin/sh, but it seems that it will take time to dig deeper into why it is being substituted, so at another time.

https://ja.wikipedia.org/wiki/Debian_Almquist_shell

Recommended Posts

How to execute multiple commands in docker-compose.yml
How to use named volume in docker-compose.yml
How to execute tasks in parallel in Swift in Swift Package
How to define multiple orm.xml in Spring4, JPA2.1
How to check Rails commands in the terminal
How to execute with commands of normal development language in Docker development environment
How to use Lombok in Spring
How to find May'n in XPath
How to hide scrollbars in WebView
How to run JUnit in Eclipse
How to iterate infinitely in Ruby
[Rails] How to write in Japanese
How to run Ant in Gradle
How to master programming in 3 months
How to learn JAVA in 7 days
How to get parameters in Spark
How to install Bootstrap in Ruby
How to use InjectorHolder in OpenAM
How to use classes in Java?
How to name variables in Java
How to set Lombok in Eclipse
[Swift] How to replace multiple strings
How to execute Ruby irb (interactive ruby)
How to concatenate strings in java
How to install Swiper in Rails
[Rails] How to execute "rails db: create" etc. in production environment EC2
How to call multiple names at once in the same category
How to execute a contract using web3j
[swift5] How to specify color in hexadecimal
How to implement search functionality in Rails
How to implement date calculation in Java
Multilingual Locale in Java How to use Locale
How to change app name in rails
How to get date data in Ruby
How to use custom helpers in rails
Note to have multiple values in HashMap
How to filter JUnit Test in Gradle
How to standardize header footer in Thymeleaf
How to include Spring Tool in Eclipse 4.6.3?
Execute blocking processing in reactor in multiple threads
How to do base conversion in Java
[Swift] How to fix Label in UIPickerView
How to have params in link_to method
How to use Docker in VSCode DevContainer
How to use MySQL in Rails tutorial
How to fix system date in JUnit
How to implement coding conventions in Java
How to embed Janus Graph in Java
[rails] How to configure routing in resources
How to map tsrange type in Hibernate
How to get the date in java
How to implement ranking functionality in Rails
How to use environment variables in RubyOnRails
How to implement asynchronous processing in Outsystems
How to publish a library in jCenter
How to specify id attribute in JSF
Understand in 5 minutes !! How to use Docker
How to overwrite Firebase data in Swift
How to use credentials.yml.enc introduced in Rails 5.2
How to switch between multiple Java versions
How to assemble JSON directly in Jackson