Docker: bash terminal starts without prompt - bash

I have a simple container that looks like this:
FROM devbox/rails3.2.1
RUN apt-get install -y -q libmysql-ruby libmysqlclient-dev
RUN apt-get install -y -q libqtwebkit-dev
EXPOSE 3000
CMD /bin/bash
where devbox/rails3.2.1 is a container I made that starts with 'FROM ubuntu' and installs Ruby on Rails. This is a running in a Vagrant Virtual Box VM using Ubuntu 12.04.3 LTS. When I run this using:
docker run -t -i -name myapp -p 3000:3000 -v /src/myapp:/src/myapp -link myappsql:myappsql devbox/myapp
The container starts, but my terminal shows a blank line with no prompt and typing doesn't do anything. If I run docker ps I can see that the container is running. Even stranger, If I open a second terminal and run 'docker attach myapp' I get a functioning terminal (though I have to press enter first) and if I switch back to my first terminal and type, the output appears in my second terminal!
Any help much appreciated.

That all sounds like expected functionality.
When doing the "docker run" command put the "/bin/bash" in it to immediately have the bash available to you without having to attach first.
docker run -t -i -name myapp -p 3000:3000 -v /src/myapp:/src/myapp -link myappsql:myappsql devbox/myapp /bin/bash

Related

Jenkins console does not show the output of command runs on docker container

Running below command to execute my tests on docker container
sudo docker exec -i 6d49272f772c bash -c "mvn clean install test"
Above command running on Jenkins execute bash. But Jenkins console does not show the logs for test execution.
I had a similar problem with docker start (which is similar to docker exec). I used the -i option and it would work fine outside Jenkins, but the console in Jenkins didn't show any output from this command. I replaced -i with -a similar to the following:
sudo docker container create -it --name container-name some-docker-image some-command
sudo docker container start -a container-name
sudo docker container rm -f container-name
The docker exec method doesn't have a -a option so possibly removing the -i option would work too (since you are not interacting with the container in Jenkins), so if that doesn't work than you can convert to the following commands and achieve similar results with standard out being captured.

I am unable to execute netcat command within docker bash terminal?

I am a beginner in docker . I have installed docker-ce in my ubuntu 18.04 machine using commandsudo apt install docker-ce
As part of a tutorial , I am trying to establish connection between containers by executing series of below commands.
Below command will turn on ports 1234/4321 to listen to traffic inside/outside of containers i'm going to use.
root#ghost-SVE9999CNS:/home/ghost# docker run --rm -ti -p 1234:1234 -p 4321:4321 --name echo-server ubuntu:18.04 bash
Now, I wanted to run netcat commands within docker bash terminal.
root#xxxyyyyzzzz12:/# nc -lp 1234 | nc -lp 4321
Once i inovke above command from my terminal.. Its giving errors "nc: command not found"
bash: nc: command not found
bash: nc: command not found
Later, I have done enough research and i never found any official docker solution for this problem.
Please could anyone help me out installing netcat within docker-ce.
I've tried commands like below.
apt-get install netstat
apt-get install nc
But, no luck.
nc is not installed by default on ubuntu:18.04 image, so you have to install it :
apt-get update && apt-get install -y netcat
apt-get update is necessary to first update list of packages (when the container is started, this list is empty). Once done, you can run nc -lp 1234 from the container.
To test all works as you expected, you can then :
run from a shell (on your host) something like telnet container_ip 1234 or telnet localhost 1234 (since ports have been forwarded)
type something
look at the container output to see what you typed in your host shell
It is not necessary to use ubuntu:18.04 to follow the tutorial, you can use ubuntu:14.04 for example, in which nc installed by default.
docker run --rm -ti -p 1234:1234 -p 4321:4321 --name echo-server ubuntu:14.04 bash

docker error on windows : the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty' [duplicate]

This question already has answers here:
Error "The input device is not a TTY"
(16 answers)
Closed 2 years ago.
After I run this
docker run --rm -v "/c/users/vipul rao/documents/github/wappalyzer:/opt/wappalyzer" -it wappalyzer/dev
I am getting the following error
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
What should I use here? I am running Docker on Windows 8 in MINGW64.
As suggested by the error message you obtain, you should try to use winpty (which is installed by default with Git-Bash) and thus run:
winpty docker run --rm -v "/c/users/vipul rao/documents/github/wappalyzer:/opt/wappalyzer" -it wappalyzer/dev
If this works, you may want to set a Bash alias to avoid manually prepending winpty all the time:
echo "alias docker='winpty docker'" >> ~/.bashrc
or
echo "alias docker='winpty docker'" >> ~/.bash_profile
If you are using Git Bash you can try like this
winpty docker run -it ubuntu
This problem occurs when running with -it option using bash terminal on windows. You can use Powershell to resolve this issue.
This works for me.
I am using git bash on windows
winpty docker-compose exec app ls -l
Remove -it from the command. If you want to keep it interactive then keep -i
Don't use alias docker="winpty docker". It solves your problem but break pipes.
$ winpty docker run -ti ubuntu
root#e85cff7d1670:/# exit
$ wintpy docker run ubuntu bash HELLO
HELLO
$ wintpy docker run ubuntu bash HELLO | cat
stdout is not a tty
Copy this to your .bashrc. This script uses winpty docker only if -ti is used.
function docker(){
for param; do if [[ "$param" == "-ti" ]] || [[ "$param" == "-it" ]]; then
winpty docker "$#"; return
fi; done;
command docker "$#"
}
docker run -ti ubuntu becomes winpty docker run -ti ubuntu avoids error: the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'"
docker run ubuntu echo "what's up" | cat becomes command docker run echo "what'up" | cat avoids error: stdout is not a tty
The script only looks if there is a '-it' parameter without checking if it is inside a 'docker run' sentence... but it does the trick for my uses.
Did you start "Docker Quickstart Terminal"? I was trying to run
$ docker run -i -t redcricket/react-tutorial:latest /bin/bash
on windows from a Cygwin bash shell and got the same error:
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
Then I remembered that when I installed docker on my windows 10 system something called "Docker Quickstart Terminal" got installed. You need to start that first from that dumb windows 'Type here to search' thing on the task bar:
That launches this …
… you can run your docker commands there without getting that error or running winpty.
The problem is with gitbash however with the powershell it is working fine ..
Happened to me. From Git Bash, on Windows 8 running Docker Toolbox. There are two things happening. From git bash, we do not seem to have complete escalated privilege to the docker daemon (even though i'm running git bash with administrative privileges).
Thus:
Try running the command from your docker terminal. (gives you privilege).
To compensate for errors from Window's folder naming formats, don't forget to quote the path.. (to escape spaces and/or capitalization errors) say
From:
docker run -v $(pwd):/data image_ref
To:
docker run -v "$(pwd):/data" image_ref
(notice the enclosing quotes in the latter around $(pwd):/data).
Just add 'winpty' in start of your cmd ,Try below:
$ winpty docker.exe run --rm -v "/c/users/vipul rao/documents/github/wappalyzer:/opt/wappalyzer" -it wappalyzer/dev
Why this happens? More details here:
http://willi.am/blog/2016/08/08/docker-for-windows-interactive-sessions-in-mintty-git-bash/
Got this error for running docker-compose exec workspace bash
So just prefix with winpty winpty docker-compose exec workspace bash
It may be that you're not running your commands within the Docker terminal. If you don't, you may not be properly connected to the Docker daemon and won't be able to interact correctly.
Make sure you're running commands in the actual Docker Terminal.
For those using WSL and running Docker for windows inside of cmder or conemu I would recommend to not to use Docker which is installed on windows in 'Program Files' but instead install Docker inside WSL on ubuntu/linux. Do remember though that you can't run Docker itself from within WSL, you must connect to Docker running on windows from the linux Docker client installed in WSL.
To install Docker on WSL
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
Your options for running actual Docker commands are to either:
Connect to Docker using the switch -H
docker -H localhost:2375 run -it -v /mnt/c/code:/var/app -w "/var/app" centos:7
Or set the environment variable docker_host
export DOCKER_HOST=tcp://localhost:2375
Either way you are now be able to interactively connect to a running Docker container
you can try with Cmder tool it will work. Its not working with Gitbash
In addition to above mentioned solutions.
In case you are getting this error for docker attach
example: docker attach alpine1
error: the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
Solution: Adding winpty before docker command i.e. winpty docker attach should work.
example: winpty docker attach alpine1
Note: I was getting this error while using base on windows and this solution worked for me.
I had the same error when trying to run the docker-compose exec command.
In the help documentation docker-compose exec --help it shows how you can disable the pseudo-tty allocation by adding -T to your command options in the following way:
docker-compose exec -T
From the help documentation:
-T Disable pseudo-tty allocation. By default docker-compose exec allocates a TTY.
If you are using gitbash the problem is when setting the terminal emulator for for using with Git bash.setting the emurator
Instead you can change the emulator to the first options or use the
winpty command before your docker run command

Docker run/star/exec?

Hi i have build and install ziftrCoin wallet on a ubuntu image.
8084e9de3c23 ubuntu:latest "/bin/bash" 25 hours ago Up About a minute 0.0.0.0:10332->10332/tcp ziftrCoin
The problem is that ziftrcoind closing after i exit the container.
Try to run docker exec -it ziftrCoin /root/64/./ziftrcoind the program start but i get connected to the container. Same problem if i exit.
So how to update / edit the COMMAND when i start the container with "ziftrCoin /root/64/./ziftrcoind" and not "/bin/bash"?
UPDATE
IF i build it run it i dont get it to stay open..
docker run -d ziftr
252554f38c2a41bdd29875bcb6ab7b6bbe98522e16828b1f8b06d8899bc5134c
docker run -it ziftr
ZiftrCOIN server starting
FROM ubuntu
MAINTAINER Krister Johansson <hello#nodejs.how>
WORKDIR /var/ziftrCoin
RUN apt-get update
RUN apt-get install -y wget
RUN wget "https://d19y4lldx7po3t.cloudfront.net/assets/downloads/0.9.3/ziftrcoin-0.9.3-linux64.tar.gz"
RUN tar -xvzf ziftrcoin-0.9.3-linux64.tar.gz
RUN rm ziftrcoin-0.9.3-linux64.tar.gz
ADD ./src/ziftrcoin.conf /root/.ziftrcoin/ziftrcoin.conf
EXPOSE 10332 11332
CMD ["64/./ziftrcoind"]
For Docker, when the process with pid 1 (inside the container) quits, it will quit too (and kill all other processed that were running in that container). This is what happens to you as /bin/bash is the process with pid 1. What you need to do is set ziftrcoind process as pid 1.
You did not provide a Dockerfile or a docker run command but I assume you run something like docker run ziftrcoin (where ziftrcoin would be the name of the image you build) and you don't have a CMD in your Dockerfile.
The idea would be either to give docker a default command, using CMD in your Dockerfile or give it the command to run when issuing the docker run.
Let's see the how the Dockerfile would look like :
FROM Ubuntu
RUN # … Install ziftrcoind
CMD ["/root/64/./ziftrcoind"]
If you build this image, when running it, the default command would be /root/64/./ziftrcoind instead of /bin/bash. You could also do docker run ziftrcoint /root/64/./ziftrcoind to achieve the same effect.
As Kevan Ahlquist commented, if you want to run it in background, you can use the flag -d : docker run -d ziftrcoin (with or without the command, depending if you have the CMD in your Dockerfile or not).
Problem found!
I had deamon=1 in ziftrcoin.conf after removing it it workt!
Uploaded it to git.
https://github.com/nodejshow/docker-ziftrcoind

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