How to run docker image , take ssh of container and bind port to "49" in single cmd? - bash

I wanted to run the image and take the ssh (bin/bsh) of container at the same time.
To start a container and take ssh
docker run -i -t --entrypoint /bin/bash <Image ID>
But in above cmd, I am not able to bind port to 49.

I think I found it.
docker run -p 8046:49 -i -t --entrypoint /bin/bash [Image Id]
Above command start the container from image , bind port "8046" to service running on port "49" and also give you terminal of that image.
Thanks for all yours comment.

Related

Piping docker run container ID to docker exec

In my development, I find myself issuing a docker run command followed by a docker exec command on the resulting container ID quite frequently. It's a little annoying to have to copy/paste the container ID between commands, so I was trying to pipe the container ID into my docker exec command.
Here's my example command.
docker run -itd image | xargs -i docker exec -it {} bash
This starts the container, but then I get the following error.
the input device is not a TTY
Does anyone have any idea how to get around this?
Edit: I also forgot to mention I have an ENTRYPOINT defined and cannot override that.
Do this instead:
ID=$(docker run -itd image) && docker exec -it $ID bash
Because xargs executes it arguments without allocating a new tty.
If you just want to "bash"-into the container you do not have to pass the container-id around. You can simply run
docker run -it --rm <image> /bin/bash
For example, if we take the ubuntu base image
docker run -it --rm ubuntu /bin/bash
root#f80f83eec0d4:/#
from the documentation
-t : Allocate a pseudo-tty
-i : Keep STDIN open even if not attached
--rm : Automatically remove the container when it exits
The command /bin/bash overwrites the default command that is specified with the CMD instruction in the Dockerfile.

How to ssh+bash into Docker container in a single command

I need to log in to a bash console within a docker container, which runs in a remote host.
The following commands work:
(local)$ ssh -i myKey user#remoteHost
(remote)$ docker exec -it myContainer /bin/bash
Note that I use passwordless authentication with SSH. My scenario is a bit more involved, including a script to get into a single command (which would actually also figure out docker container ID), this is enough to show the problem. When I try to run in a single command, I get the following error:
(local)$ ssh -i myKey user#remoteHost "docker exec -it myContainer /bin/bash"
cannot enable tty mode on non tty input
How can I run this SSH and get past the "cannot enable tty" error?
Use the -t option (twice) with ssh:
ssh -tt -i myKey user#remoteHost docker exec -it myContainer /bin/bash
you can use the command (from your pc) docker-machine with this you are able to connect to the docker server (if the api are exposed) an manage the docker like your local environment (docker ps, docker run etc etc)
documentation:
https://docs.docker.com/machine/

Daemon started with "docker run daemon" is not working

docker run -itp 26542:26542 stack/vowpall vw -t -i /home/alex/cb.model --daemon --port 26542
when I run this command there is no daemon listening. When I run
docker ps
there are no processes
but when I go to docker container bash and run
vw -t -i /home/alex/cb.model --daemon --port 26542
there is a daemon listening, also visible in docker ps. Any ideas?
The problem is that the daemon is forking to the background and a Docker container only runs as long as its main process. When the daemon forks to the background, the main process ends and so does the container. You just need to keep the application running in the foreground, which probably just means removing the --daemon argument.
Also, you only need the -it arguments if you want a shell, so you can remove them as well. If you want to get the shell on your host back after running the docker command, add -d so that the client disconnects after starting the container e.g:
docker run -d p 26542:26542 stack/vowpall vw -t -i /home/alex/cb.model --port 26542

Windows Boot2Docker leaving a container and returning to B2D

If I am running Boot2Docker on windows 7, and I connect to a container by running a command like docker run -it ubuntu:14.04 /bin/bash, how can I "disconnect" from the container and return the prompt to the boot2docker images command prompt?
Ideally I'd like to know both how to kill the container, and how to push the container into the background and then return it to the foreground later.
What you seem to be looking for is the -d option for the docker run command which starts the container on background. You can then access the container easily with command like this (found from Timur Fayzrakhmanov's answer on AskUbuntu)
sudo docker exec -i -t <your_id> bash
where you replace the your_id with something like 665b4a1e17b6.

Docker. How to get bash\ssh inside runned container (run -d)?

I want to ssh or bash into runned docker container. Please, see example:
$ sudo docker run -d webserver
webserver is clean image from ubuntu:14.04
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
665b4a1e17b6 webserver:latest /bin/bash ... ... 22/tcp, 80/tcp loving_heisenberg
now I want to get something like this (go into runned container):
$ sudo docker run -t -i webserver (or maybe 665b4a1e17b6 instead)
$ root#665b4a1e17b6:/#
Previously I used Vagrant so I want to get behavior similar to vagrant ssh. Please, could anyone help me?
After the release of Docker version 1.3, the correct way to get a shell or other process on a running container is using the docker exec command. For example, you would run the following to get a shell on a running container:
docker exec -it myContainer /bin/bash
You can find more information in the documentation.
The answer is docker attach command.
For information see: https://askubuntu.com/a/507009/159189

Resources