summaryrefslogtreecommitdiff
path: root/devdocs/docker/compose%2Ffaq%2Findex.html
blob: dd913ed231f9d8b9567f61290e19d89a0ad38707 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<h1>Frequently asked questions</h1>

<p>If you don’t see your question here, feel free to drop by <a href="https://dockercommunity.slack.com/archives/C2X82D9PA">#docker-compose</a> on the <a href="https://dockr.ly/slack">Docker Community Slack</a>.</p> <h2 id="can-i-control-service-startup-order">Can I control service startup order?</h2> <p>Yes - see <a href="../startup-order/index">Controlling startup order</a>.</p> <h2 id="why-do-my-services-take-10-seconds-to-recreate-or-stop">Why do my services take 10 seconds to recreate or stop?</h2> <p>Compose stop attempts to stop a container by sending a <code class="language-plaintext highlighter-rouge">SIGTERM</code>. It then waits for a <a href="../reference/stop/index">default timeout of 10 seconds</a>. After the timeout, a <code class="language-plaintext highlighter-rouge">SIGKILL</code> is sent to the container to forcefully kill it. If you are waiting for this timeout, it means that your containers aren’t shutting down when they receive the <code class="language-plaintext highlighter-rouge">SIGTERM</code> signal.</p> <p>There has already been a lot written about this problem of <a href="https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86">processes handling signals</a> in containers.</p> <p>To fix this problem, try the following:</p> <ul> <li> <p>Make sure you’re using the exec form of <code class="language-plaintext highlighter-rouge">CMD</code> and <code class="language-plaintext highlighter-rouge">ENTRYPOINT</code> in your Dockerfile.</p> <p>For example use <code class="language-plaintext highlighter-rouge">["program", "arg1", "arg2"]</code> not <code class="language-plaintext highlighter-rouge">"program arg1 arg2"</code>. Using the string form causes Docker to run your process using <code class="language-plaintext highlighter-rouge">bash</code> which doesn’t handle signals properly. Compose always uses the JSON form, so don’t worry if you override the command or entrypoint in your Compose file.</p> </li> <li> <p>If you are able, modify the application that you’re running to add an explicit signal handler for <code class="language-plaintext highlighter-rouge">SIGTERM</code>.</p> </li> <li> <p>Set the <code class="language-plaintext highlighter-rouge">stop_signal</code> to a signal which the application knows how to handle:</p> </li> </ul> <div class="highlight"><pre class="highlight" data-language="">services:
  web:
    build: .
    stop_signal: SIGINT
</pre></div> <ul> <li>If you can’t modify the application, wrap the application in a lightweight init system (like <a href="https://skarnet.org/software/s6/">s6</a>) or a signal proxy (like <a href="https://github.com/Yelp/dumb-init">dumb-init</a> or <a href="https://github.com/krallin/tini">tini</a>). Either of these wrappers takes care of handling <code class="language-plaintext highlighter-rouge">SIGTERM</code> properly.</li> </ul> <h2 id="how-do-i-run-multiple-copies-of-a-compose-file-on-the-same-host">How do I run multiple copies of a Compose file on the same host?</h2> <p>Compose uses the project name to create unique identifiers for all of a project’s containers and other resources. To run multiple copies of a project, set a custom project name using the <a href="../reference/index"><code class="language-plaintext highlighter-rouge">-p</code> command line option</a> or the <a href="../reference/envvars/index#compose_project_name"><code class="language-plaintext highlighter-rouge">COMPOSE_PROJECT_NAME</code> environment variable</a>.</p> <h2 id="whats-the-difference-between-up-run-and-start">What’s the difference between <code class="language-plaintext highlighter-rouge">up</code>, <code class="language-plaintext highlighter-rouge">run</code>, and <code class="language-plaintext highlighter-rouge">start</code>?</h2> <p>Typically, you want <code class="language-plaintext highlighter-rouge">docker-compose up</code>. Use <code class="language-plaintext highlighter-rouge">up</code> to start or restart all the services defined in a <code class="language-plaintext highlighter-rouge">docker-compose.yml</code>. In the default “attached” mode, you see all the logs from all the containers. In “detached” mode (<code class="language-plaintext highlighter-rouge">-d</code>), Compose exits after starting the containers, but the containers continue to run in the background.</p> <p>The <code class="language-plaintext highlighter-rouge">docker-compose run</code> command is for running “one-off” or “adhoc” tasks. It requires the service name you want to run and only starts containers for services that the running service depends on. Use <code class="language-plaintext highlighter-rouge">run</code> to run tests or perform an administrative task such as removing or adding data to a data volume container. The <code class="language-plaintext highlighter-rouge">run</code> command acts like <code class="language-plaintext highlighter-rouge">docker run -ti</code> in that it opens an interactive terminal to the container and returns an exit status matching the exit status of the process in the container.</p> <p>The <code class="language-plaintext highlighter-rouge">docker-compose start</code> command is useful only to restart containers that were previously created, but were stopped. It never creates new containers.</p> <h2 id="can-i-use-json-instead-of-yaml-for-my-compose-file">Can I use json instead of yaml for my Compose file?</h2> <p>Yes. <a href="https://stackoverflow.com/a/1729545/444646">Yaml is a superset of json</a> so any JSON file should be valid Yaml. To use a JSON file with Compose, specify the filename to use, for example:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker-compose -f docker-compose.json up
</pre></div> <h2 id="should-i-include-my-code-with-copyadd-or-a-volume">Should I include my code with <code class="language-plaintext highlighter-rouge">COPY</code>/<code class="language-plaintext highlighter-rouge">ADD</code> or a volume?</h2> <p>You can add your code to the image using <code class="language-plaintext highlighter-rouge">COPY</code> or <code class="language-plaintext highlighter-rouge">ADD</code> directive in a <code class="language-plaintext highlighter-rouge">Dockerfile</code>. This is useful if you need to relocate your code along with the Docker image, for example when you’re sending code to another environment (production, CI, etc).</p> <p>You should use a <code class="language-plaintext highlighter-rouge">volume</code> if you want to make changes to your code and see them reflected immediately, for example when you’re developing code and your server supports hot code reloading or live-reload.</p> <p>There may be cases where you want to use both. You can have the image include the code using a <code class="language-plaintext highlighter-rouge">COPY</code>, and use a <code class="language-plaintext highlighter-rouge">volume</code> in your Compose file to include the code from the host during development. The volume overrides the directory contents of the image.</p> <h2 id="where-can-i-find-example-compose-files">Where can I find example compose files?</h2> <p>There are <a href="https://github.com/search?q=in%3Apath+docker-compose.yml+extension%3Ayml&amp;type=Code">many examples of Compose files on GitHub</a>.</p> <h2 id="compose-documentation">Compose documentation</h2> <ul> <li><a href="../index">User guide</a></li> <li><a href="../install/index">Installing Compose</a></li> <li><a href="../gettingstarted/index">Getting Started</a></li> <li><a href="../reference/index">Command line reference</a></li> <li><a href="../compose-file/index">Compose file reference</a></li> <li><a href="../samples-for-compose/index">Sample apps with Compose</a></li> </ul> 
<p><a href="https://docs.docker.com/search/?q=documentation">documentation</a>, <a href="https://docs.docker.com/search/?q=docs">docs</a>, <a href="https://docs.docker.com/search/?q=docker">docker</a>, <a href="https://docs.docker.com/search/?q=compose">compose</a>, <a href="https://docs.docker.com/search/?q=faq">faq</a></p>
<div class="_attribution">
  <p class="_attribution-p">
    &copy; 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br>
    <a href="https://docs.docker.com/compose/faq/" class="_attribution-link">https://docs.docker.com/compose/faq/</a>
  </p>
</div>