<p>For building docker image using <code>docker-compose</code> you can add <code>build:</code> field to the service you want to build and assign to it the path of the <code>Dockerfile</code> for example:</p>

<pre><code>version: '2'
services:
  web:
    build: .
    ports:
     - "8080:80"
    volumes:
     - /project:/var/www/html
</code></pre>

<p>This example define a web service which:</p>

<ul>
<li>Uses an image that’s built from the <code>Dockerfile</code> in the current directory.</li>
<li>Forwards the exposed port 80 on the container to port 8080 on the
host machine</li>
<li>Mounts the project directory on the host to <code>/project</code> inside the
container, allowing you to modify the code without having to rebuild
the image.</li>
</ul>

<p>To build the image, simply issue the build command via docker-compose, as such: <code>docker-compose build</code>.</p>

CC BY-SA 3.0
2017-10-31T04:27:56.903Z
Additionally, you can specify an image name by providing the "image" key. See https://docs.docker.com/compose/compose-file/#build
Mathieu Mitchell
CC BY-SA 3.0
2017-08-02T01:51:13.620Z
2017-10-31T22:11:56.537Z
2017-10-31T22:11:56.537Z
Wissam Roujoulah
<p>I've got a local application working using <code>docker-compose up</code>, this gets me the servers I need and they function just fine locally.</p>

<p>Now I've tried getting a <code>build.sh</code> started, but I can't figure out how to build a docker image using either <code>docker-compose</code> or just regular <code>docker-cli</code> with the final result of the build process. (The <code>/dist/</code> folder).</p>

<p>Could somebody explain to me how a regular process like this would look like, and what steps a build process would walk through in docker terms?
Would I need a seperate command to package it for deployment? Is there a separate configuration required? </p>

<docker>
Getting a docker build ready for (Heroku) deployment?
Bjorn Schijff
# Getting a docker build ready for (Heroku) deployment?

(Asked by: username_0 on 2017-07-31)

I've got a local application working using `docker-compose up`, this gets me the servers I need and they function just fine locally.

Now I've tried getting a `build.sh` started, but I can't figure out how to build a docker image using either `docker-compose` or just regular `docker-cli` with the final result of the build process. (The `/dist/` folder).

Could somebody explain to me how a regular process like this would look like, and what steps a build process would walk through in docker terms?
Would I need a seperate command to package it for deployment? Is there a separate configuration required?

**Tags:** docker


---

## 1 answers

### Answer by username_1 on 2017-08-02. Score: 1

For building docker image using docker-compose you can add build: field to the service you want to build and assign to it the path of the Dockerfile for example:
version: '2'
services:
  web:
    build: .
    ports:
     - "8080:80"
    volumes:
     - /project:/var/www/html

This example define a web service which:

Uses an image that’s built from the Dockerfile in the current directory.
Forwards the exposed port 80 on the container to port 8080 on the
host machine
Mounts the project directory on the host to /project inside the
container, allowing you to modify the code without having to rebuild
the image.

To build the image, simply issue the build command via docker-compose, as such: docker-compose build.

> **Comments:**
> **username_2**: Additionally, you can specify an image name by providing the "image" key. See https://docs.docker.com/compose/compose-file/#build  

---

