question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't open an interactive container

See original GitHub issue

I’m trying to convert a Python script from executing command line statements to using docker-py. I have a running container with MongoDB, and I want to create another container with Mongo shell.

This command-line works for me as expected:

docker run -i -t --entrypoint="mongo" mongo-image mongo-url:27017 Also succeeded converting it to separate docker create, docker start and docker attach commands, but I fail to get an interactive Mongo shell using docker-py. This is what I’m trying to do:

container = c.create_container(
        image=MONGO_IMAGE,
        entrypoint='mongo',
        command='%s:27017' % ip,
        detach=False,
        stdin_open=True,
        tty=True
    )
    c.start(container=container['Id'])
    c.attach(container=container['Id'])

but it doesn’t work (container is created, but not attached). How can I make it happen?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9

github_iconTop GitHub Comments

8reactions
elliotwoodscommented, Oct 2, 2017

my run command looks like this:

		client.containers.run(imageName
			, stdin_open = True
			, tty = True
			, name = "hacnode"
			, detach = True
			, volumes = {
				'/root' : {
					'bind' : '/mnt',
					'mode' : 'rw'
				}
			}
			, privileged = True
			, restart_policy = {
				"MaximumRetryCount": 0,
				"Name": "unless-stopped"
			}
			, network_mode = 'host'
		)

you just need to check those first lines about stdin_open and tty

4reactions
elliotwoodscommented, Oct 2, 2017

please note that the container does not become interactive within the python terminal, it just means that i can attach to the container later (this is what i want). if you want to attach to the container, then i would suggest using a system command to docker to perform this for you. trying to do this from within python sounds very messy, as the remote terminal should essentially have full control of the local terminal, which would mean a lot of actions would have to be passed through python, and the docker executable would do a much more consistent job of this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot start interactive shell with docker container
Yes docker start command should start the container, but there are some questions around here, is your container running a one-time process or ......
Read more >
Debugging docker container that won't start | by suprit shah
I will show you how to start docker container in a debug mode (interactive shell) and dive deep into investigating docker-entrypoint.sh ...
Read more >
Unable to run docker in Interactive mode - General Discussions
I was trying to run docker in interactive mode where i could login to the container. I switched to root user then I...
Read more >
How to Launch a Docker Container with an Interactive Shell
When you start a container from the Base image using Docker, Docker fetches ... running under Nginx Web Server using an interactive shell...
Read more >
Interactive Container - am I missing something?
Interactive Container - I have selected interactive content but I cannot select "Insert PDF" from the context menu - am I missing something?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found