You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an existing data-container. I'd like to create a new container with volumes from the data-container and stomp around in it interactively, or at the very least run a command and get to see Stdout. Unfortunately attaching Stdout, or anything else I've tried, doesn't work. Some code:
// vars that exist ...
// var interactive bool
// var args []string
// var DockerClient *docker.Client
volumesFrom := "existing_data_container"
opts := docker.CreateContainerOptions{
Name: "exec_" + volumesFrom,
Config: &docker.Config{
Image: "myimage",
User: "root",
AttachStdout: true,
AttachStderr: true,
NetworkDisabled: true,
},
HostConfig: &docker.HostConfig{
VolumesFrom: []string{volumesFrom},
},
}
if interactive {
opts.Config.AttachStdin = true
opts.Config.OpenStdin = true
opts.Config.Cmd = []string{"/bin/bash"}
} else {
opts.Config.Cmd = args
}
cont, err := DockerClient.CreateContainer(opts)
if err != nil {
return err
}
id_main := cont.ID
logger.Infoln("Data Container ID: " + id_main)
// start the container
if err := DockerClient.StartContainer(id, opts.HostConfig); err != nil {
return err
}
logger.Infof("Waiting for %s to exit so we can remove the container\n", id_main)
if err := waitContainer(id_main); err != nil {
return err
}
logger.Infof("Removing container %s\n", id_main)
if err := removeContainer(id_main); err != nil {
return err
}
return nil
If I pass some command, say args = []string{"ls"}, I get something like:
Data Container ID: cb9913cd3d89bd8a303475acf96c6f83cdbae01e40da6b5d9c9c218aa6101575
Waiting for cb9913cd3d89bd8a303475acf96c6f83cdbae01e40da6b5d9c9c218aa6101575 to exit so we can remove the container
Removing container cb9913cd3d89bd8a303475acf96c6f83cdbae01e40da6b5d9c9c218aa6101575
So it works but no output from ls.
If I avoid removing the container and check docker logs, the output of ls is there and correct, but it doesn't make it to my terminal's stdout. And if I try to do the interactive thing, it just hangs.
Of course it works just fine from the cli:
docker run --volumes-from existing_data_container myimage ls
Any idea what I'm doing wrong?
The text was updated successfully, but these errors were encountered:
I think the bug here is that the documentation is possibly not clear enough as to what the meaning of AttachStdout is. For that you have to look at for the docker docs themselves, but those aren't very clear either: http://docs.docker.com/engine/reference/api/docker_remote_api_v1.20/#create-a-container. It just says "Attaches stdout" which I take to mean "don't send stdout to /dev/null". To actually obtain the stream you need to run a separate attach command. Beware though, that this isn't easy!
I have an existing data-container. I'd like to create a new container with volumes from the data-container and stomp around in it interactively, or at the very least run a command and get to see Stdout. Unfortunately attaching Stdout, or anything else I've tried, doesn't work. Some code:
If I pass some command, say
args = []string{"ls"}
, I get something like:So it works but no output from
ls
.If I avoid removing the container and check
docker logs
, the output ofls
is there and correct, but it doesn't make it to my terminal's stdout. And if I try to do the interactive thing, it just hangs.Of course it works just fine from the cli:
docker run --volumes-from existing_data_container myimage ls
Any idea what I'm doing wrong?
The text was updated successfully, but these errors were encountered: