<p><code>docker.containers.create()</code> is <a href="https://docker-py.readthedocs.io/en/stable/containers.html" rel="nofollow noreferrer">documented</a> to:</p>

<blockquote>
  <p>Create a container without starting it. Similar to <code>docker create</code>.</p>
</blockquote>

<p>Either call <code>docker.containers.run()</code> instead, or given the container object returned from <code>create()</code>, call <code>ingreedy.start()</code>.</p>

<p>(<code>docker ps</code> by default only shows running containers; <code>docker ps -a</code> should show the container in a "created" state.)</p>

CC BY-SA 4.0
2020-05-11T05:22:02.087Z
ahh thank you!!
Ta Mu
CC BY-SA 4.0
2020-05-10T23:14:06.967Z
2020-05-10T23:14:06.967Z
David Maze
<p>Consider the following setup.</p>

<p>Precondition: have a healthy image i.e. service starts up.</p>

<p>E.g.</p>

<pre><code>docker run -d IMAGE
</code></pre>

<p>Then, with the Python plugin docker-py, consider the following code which should be equivalent, only with added port mapping.</p>

<pre><code>ingreedy = client.containers.create("openfoodbroker/ingreedy.service", 
                                     name="ingreedy_service",
                                     detach=True,
                                     ports={'5000': 5000})
print(ingreedy.id)
</code></pre>

<p>This code prints out the container ID and I can remove the container using <code>docker rm -f</code>, but:</p>

<ul>
<li>port 5000 is not open;</li>
<li>the container does not show up on <code>docker ps</code></li>
</ul>

<p>Any ideas?</p>

<docker><python>
Strange behaviour with docker-py
Ta Mu
# Strange behaviour with docker-py

(Asked by: username_0 on 2020-05-10)

Consider the following setup.
Precondition: have a healthy image i.e. service starts up.
E.g.
docker run -d IMAGE

Then, with the Python plugin docker-py, consider the following code which should be equivalent, only with added port mapping.
ingreedy = client.containers.create("openfoodbroker/ingreedy.service", 
                                     name="ingreedy_service",
                                     detach=True,
                                     ports={'5000': 5000})
print(ingreedy.id)

This code prints out the container ID and I can remove the container using docker rm -f, but:

port 5000 is not open;
the container does not show up on docker ps

Any ideas?

**Tags:** docker, python


---

## 1 answers

### Answer by username_1 on 2020-05-10. Score: 3 | Accepted answer

`docker.containers.create()` is [documented](https://docker-py.readthedocs.io/en/stable/containers.html) to:

> Create a container without starting it. Similar to `docker create`.

Either call `docker.containers.run()` instead, or given the container object returned from `create()`, call `ingreedy.start()`.

(`docker ps` by default only shows running containers; `docker ps -a` should show the container in a "created" state.)

> **Comments:**
> **username_0**: ahh thank you!!  

---

