Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't start container. Unsure why #3078

Closed
James-Ilosta opened this issue Dec 21, 2022 · 3 comments
Closed

Can't start container. Unsure why #3078

James-Ilosta opened this issue Dec 21, 2022 · 3 comments

Comments

@James-Ilosta
Copy link

I’m trying to run docker at the moment from the python api. I’m just trying to make a container and then run commands using the exec_run command, however, my container seems to exit immediately after using the following:

import docker
from docker.types import Mount

import os

client = docker.from_env()
source_directory = "C:\Users\usr\data"
target="/data"
volume=os.getcwd() + "/data"

image_selected='openfoam/openfoam7-paraview56'
container=client.api.create_container(image_selected)
container=client.containers.get(container['Id'])
print(container)
container.start()

I’ve tried to add in a pause command with the following:
container=client.api.create_container(image_selected, command="while true; do sleep 10000000; done")

and this doesn’t have any effect and the container still exits immediately.
image

I don’t suppose you would have any idea on how to troubleshoot. As far as I’m aware there are no errors that are outputted.

Here is the terminal output. I tried to use container.start() 2 times so that is why there are 3 of the initial messages:

image

Do you have any ideas?

@semwai
Copy link

semwai commented Dec 21, 2022

Hello, this works in my project:

self.container = client.containers.run(
            self.image,
            command='sleep 36000',
            working_dir='/app',
            volumes=[f'{self.volume.id}:/app'],
            tty=False,
            detach=True,
            network_disabled=True,
            name=f"container_{unique_id}"
        )

there may be a problem with the 'openfoam/openfoam7-paraview56' image, try another one to test

@James-Ilosta
Copy link
Author

Thanks for the comment. I just tried another image and the same happens

@naufalafif
Copy link

seems to be the problem with the image
the only way I found to make it run is by changing the entrypoint. using entrypoint + command also doesn't work
executing the original entrypoint from interactive mode is working tho. look at image below

import docker
from docker.types import Mount

import os

client = docker.from_env()

image_selected='openfoam/openfoam7-paraview56'
client.images.pull(image_selected)
container=client.api.create_container(
    image_selected,
    entrypoint=["/bin/sh","-c","sleep 1h"],
)
container=client.containers.get(container['Id'])
print(container)
container.start()

interactive mode

Screenshot 2023-04-05 073305

@milas milas closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants