# Commit vs build

**URL:** <https://forums.docker.com/t/commit-vs-build/26967>\
**Category:** General\
**Created:** [January 10, 2017, 4:02pm UTC](https://forums.docker.com/t/commit-vs-build/26967 "2017-01-10T16:02:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olafbar](https://avatars.discourse-cdn.com/v4/letter/o/90db22/32.png) [@olafbar](https://forums.docker.com/u/olafbar)\
**Post date:** [January 10, 2017, 4:02pm UTC](https://forums.docker.com/t/commit-vs-build/26967/1 "2017-01-10T16:02:09Z")

</div>

Hello,  
I have a question about comparison build and commit  
Example : image mongo.

1. run -it --name M1 mongo /bin/bash  
then inside contener:

apt-get update && apt-get install ssh  
useradd test  
echo “test:PASS” | chpasswd

on the host machine i do: docker commit M1 mongo-m1

2 The second way i make Dockerfile:  
FROM mongo:latest  
RUN apt-get -y update && apt-get -y install ssh  
RUN useradd test  
RUN echo “test:PASS” | chpasswd

and then:  
docker build -t mongo-m2 .

And finally mongo-m1 does not work properly. ie:

docker run -d mongo-m1 does not create running contener  
and  
docker run -d mongo-m2 works fine

Any suggestions ?

Regards , Olaf

---

<div class="post-metadata">

**Author:** ![dmaze](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dmaze](https://forums.docker.com/u/dmaze)\
**Post date:** [January 10, 2017, 4:26pm UTC](https://forums.docker.com/t/commit-vs-build/26967/2 "2017-01-10T16:26:10Z")

</div>

> [@olafbar](#):
>
> Any suggestions ?

Never use `docker commit`. `docker build` is more reproducible, and there are a couple of actions (like setting `CMD` and `ENTRYPOINT`) that are important and difficult to do via `docker commit`.

(If you start with `docker commit`, you’ll eventually get to a point where you need to update the image, and wish you had written down the commands you had run to build the image originally…which is just a `Dockerfile`.)

Your two paths look like they should probably be close to equivalent, and I’m not sure why (or how) your `commit`ted image doesn’t work, but since your `docker build` path does work, I’d just stick with that and not worry too much about it.

---

<div class="post-metadata">

**Author:** ![olafbar](https://avatars.discourse-cdn.com/v4/letter/o/90db22/32.png) [@olafbar](https://forums.docker.com/u/olafbar)\
**Post date:** [January 10, 2017, 4:46pm UTC](https://forums.docker.com/t/commit-vs-build/26967/3 "2017-01-10T16:46:24Z")

</div>

Thanks for answer,  
There is strange especially because committed system works fine when i started it in interactive mode (–it /bin/bash)  
And i have to start mongod manually …
