Related
I recently upgraded Docker Desktop for Mac to version 2.2.0.0, and now when try to run a docker-machine command I am getting an error:
$ docker-machine --version
docker-machine: command not found
Docker Machine used to be installed with Docker, but it appears in the latest docs that this is no longer the case. What is the replacement or do I need to install Docker Machine from somewhere else?
Docker machine has been removed from later versions of Docker Desktop. Your going to need the docker-toolbox package.
Read here for install and co existence of the packages.
https://docs.docker.com/docker-for-mac/docker-toolbox/#docker-toolbox-and-docker-desktop-coexistence
For Windows, if you have chocolatey installed, you follow the steps:
open a command shell with "Run as Administrator" selected (I tested this on my work laptop).
run "choco install docker-machine"
Docker machine is now merged into the docker command, So instead of using
docker-machine init
Use
docker swarm init
And instead of
docker-machine join
Use
docker swarm join
for more command just use this:
docker swarm --help
If you already have docker-desktop & want the docker-machine command, then brew install docker-machine does the trick.
My versions of the binaries in usr/local/bin/docker and usr/local/bin/docker-compose did not change, & the version of the docker client & server, but I got the docker-machine binary extra.
run unset ${!DOCKER_*} if you want to use docker-desktop.
The docker docs are a bit confusing because they seem to address the case where you have docker-machine first, not the case where you have desktop first.
You basically need to install Docker Machine first on your local machine. Reference :- https://github.com/docker/machine/releases
$ curl -L https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine &&
chmod +x /tmp/docker-machine &&
sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
Try and run this command on bash:
curl -L https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && chmod +x /tmp/docker-machine && sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
Click here to know more about docker-machine installation
It worked for me.
Did you try brew to install it as they removed docker-machine from v2.2.0?
brew install docker-machine
Try this (both inside, and outside of container):
ss -nputl
I've done configuration by using https://codecept.io/quickstart this tutorial and try to run npx codeceptjs run --steps this command , and then I get this issue . I use for this ubuntu wsl system on windows 10 . Why do this happens ? If you need more information , pls let me know !
Looks like you try to use the WebDriver helper.
This needs a selenium server running.
The easiest is to install it via npx selenium-standalone install and then to run it via npx selenium-standalone start. In a new command line window run npx codeceptjs run --steps again.
Just stand up a Selenium server running on port 4444.
e.g.,
docker run -d -p 4444:4444 --name=selenium --rm -v /dev/shm:/dev/shm selenium/standalone-chrome
More info can be found here: https://codecept.io/quickstart-webdriver
We have the need to create a docker container that also has the db2 client installed. This container will also have some shell scripts that make use of the db2 client.
We take a base Cent OS image and then add db2 via a RUN command:
COPY db2rtcl_nr.rsp /db2install/
RUN cd /db2install && curl -o ibm_data_server_runtime_client_linuxx64_v11.1.tar.gz http://public_file_server.com/downloads/appTools/installs/db2/ibm_data_server_runtime_client_linuxx64_v11.1.tar.gz && \
tar -xvf ibm_data_server_runtime_client_linuxx64_v11.1.tar.gz && \
rm -f ibm_data_server_runtime_client_linuxx64_v11.1.tar.gz && \
rtcl/db2setup -u db2rtcl_nr.rsp -f sysreq && \
chown -R 1000:1000 /opt/ibm/db2/V11.1
ENV PATH="$PATH:/opt/ibm/db2/V11.1/bin"
The image builds ok with no errors.
However, when I try running and connecting to the container via interactive shell command:
docker run -it --entrypoint=/bin/bash db2Container
and try to invoke the db2 CLI with
db2
I get the error:
DB21018E A system error occurred. The command line processor could not
continue processing.
Whats confusing is that if I immediately run a bash shell and then invoke the db2 CLI, it works:
bash
db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 11.1.0
You can issue database manager commands and SQL statements from the command
prompt. For example:
db2 => connect to sample
db2 => bind sample.bnd
For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 =>
Things I have tried to diagnose the issue:
When I 1st drop into the interactive shell session, I type
env > /tmp/env1.txt
I then type bash and run
env > /tmp/env2.txt
When I diff the files, they are virtually identical EXCEPT for the variable:
SHLVL=2
which I know is just indicating that the 2nd shell is a nested shell
When I 1st drop into the interactive shell session, I type
set > /tmp/set1.txt
I then type bash and run
set > /tmp/set2.txt
When I diff the files, they are virtually identical EXCEPT for the SHLVL variable again
Why is the db2 CLI accessible after I bash in the container but not in the initial session when i have used docker run -it?
We are attempting to use this container as an executable container that has the db2 client in it to connect to external DB2 databases. We are NOT trying to run a db2 DB in a container.
What I am starting to find is that I might have an issue with how the entrypoint is defined in our Dockerfile.
Using:
ENTRYPOINT cat /dev/null && /usr/bin/bash
the DB2 client is available when I run docker run -it ContainerName without having to immediately type bash
BUT it does not work when I try to run the container as an executable docker run ContainerName
The closest I have come to the solution is this modification to the Dockerfile:
ENTRYPOINT []
CMD ["/bin/bash"]
When I run the container as an executable docker run ContainerName db2 list command options it works however NOW if I docker run -it ContainerName I dont immediately have db2 commands available without typing bash once. This is still problematic since this container will have shell script in it that need to be able to run db2 commands
After some more googling, I found this article: https://engineeringblog.yelp.com/2016/01/dumb-init-an-init-for-docker.html
Using their Github page example, I updated our Dockerfile with:
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64
RUN chmod +x /usr/local/bin/dumb-init
and also updated our Dockerfile's entrypoint with:
ENTRYPOINT ["/usr/local/bin/dumb-init", "--"]
CMD ["/bin/bash"]
The result has been that my dummy shell script (that has a db2 command in it) that lives inside of the container works when the docker container is called as an executable:
docker run myContainer /scripts/dummyDB2connect.sh
AND I can also interactively spin up and connect to the container to run db2 commands without having to type the extra bash command.
I am running the following command from my Jenkinsfile. However, I get the error "The input device is not a TTY".
docker run -v $PWD:/foobar -it cloudfoundry/cflinuxfs2 /foobar/script.sh
Is there a way to run the script from the Jenkinsfile without doing interactive mode?
I basically have a file called script.sh that I would like to run inside the Docker container.
Remove the -it from your cli to make it non interactive and remove the TTY. If you don't need either, e.g. running your command inside of a Jenkins or cron script, you should do this.
Or you can change it to -i if you have input piped into the docker command that doesn't come from a TTY. If you have something like xyz | docker ... or docker ... <input in your command line, do this.
Or you can change it to -t if you want TTY support but don't have it available on the input device. Do this for apps that check for a TTY to enable color formatting of the output in your logs, or for when you later attach to the container with a proper terminal.
Or if you need an interactive terminal and aren't running in a terminal on Linux or MacOS, use a different command line interface. PowerShell is reported to include this support on Windows.
What is a TTY? It's a terminal interface that supports escape sequences, moving the cursor around, etc, that comes from the old days of dumb terminals attached to mainframes. Today it is provided by the Linux command terminals and ssh interfaces. See the wikipedia article for more details.
To see the difference of running a container with and without a TTY, run a container without one: docker run --rm -i ubuntu bash. From inside that container, install vim with apt-get update; apt-get install vim. Note the lack of a prompt. When running vim against a file, try to move the cursor around within the file.
For docker run DON'T USE -it flag
(as said BMitch)
And it's not exactly what you are asking, but would be also useful for others:
For docker-compose exec use -T flag!
The -T key would help people who are using docker-compose exec! (It disable pseudo-tty allocation)
For example:
docker-compose -f /srv/backend_bigdata/local.yml exec -T postgres backup
or
docker-compose exec -T mysql mysql -uuser_name -ppassword database_name < dir/to/db_backup.sql
For those who struggle with this error and git bash on Windows, just use PowerShell where -it works perfectly.
If you are using git bash on windows, you just need to put
winpty
before your 'docker line' :
winpty docker exec -it some_container bash
In order for docker to allocate a TTY (the -t option) you already need to be in a TTY when docker run is called. Jenkins executes its jobs not in a TTY.
Having said that, the script you are running within Jenkins you may also want to run locally. In that case it can be really convenient to have a TTY allocated so you can send signals like ctrl+c when running it locally.
To fix this make your script optionally use the -t option, like so:
test -t 1 && USE_TTY="-t"
docker run ${USE_TTY} ...
when using 'git bash',
1) I execute the command:
docker exec -it 726fe4999627 /bin/bash
I have the error:
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
2) then, I execute the command:
winpty docker exec -it 726fe4999627 /bin/bash
I have another error:
OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused "exec: \"D:/Git/usr/bin/
bash.exe\": stat D:/Git/usr/bin/bash.exe: no such file or directory": unknown
3) third, I execute the:
winpty docker exec -it 726fe4999627 bash
it worked.
when I using 'powershell', all worked well.
Using docker-compose exec -T fixed the problem for me via Jenkins
docker-compose exec -T containerName php script.php
Same Case Here, I am running the following command throw .sh script(bash) and python .py
However, I get the same error "The input device is not a TTY".
in my case, I'm trying to take the dump from a running container of my "production" env with authentication and passing with some arguments,
then take the output of .bak file of my mssql database container.
Remove -it from the command. If you want to keep it interactive then keep -i.
you can check my .sh file and a long command taking dump.
if using windows, try with cmd , for me it works. check if docker is started.
My Jenkins pipeline step shown below failed with the same error.
steps {
echo 'Building ...'
sh 'sh ./Tools/build.sh'
}
In my "build.sh" script file "docker run" command output this error when it was executed by Jenkins job. However it was working OK when the script ran in the shell terminal.The error happened because of -t option passed to docker run command that as I know tries to allocate terminal and fails if there is no terminal to allocate.
In my case I have changed the script to pass -t option only if a terminal could be detected. Here is the code after changes :
DOCKER_RUN_OPTIONS="-i --rm"
# Only allocate tty if we detect one
if [ -t 0 ] && [ -t 1 ]; then
DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -t"
fi
docker run $DOCKER_RUN_OPTIONS --name my-container-name my-image-tag
I know this is not directly answering the question at hand but for anyone that comes upon this question who is using WSL running Docker for windows and cmder or conemu.
The trick is not to use Docker which is installed on windows at /mnt/c/Program Files/Docker/Docker/resources/bin/docker.exe but rather to install the ubuntu/linux Docker. It's worth pointing out that you can't run Docker itself from within WSL but you can connect to Docker for windows from the linux Docker client.
Install Docker on Linux
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
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
Connect to Docker for windows on the port 2375 which needs to be enabled from the settings in docker for windows.
docker -H localhost:2375 run -it -v /mnt/c/code:/var/app -w "/var/app" centos:7
Or set the docker_host variable which will allow you to omit the -H switch
export DOCKER_HOST=tcp://localhost:2375
You should now be able to connect interactively with a tty terminal session.
In Jenkins, I'm using docker-compose exec -T
eg:-
docker-compose exec -T app php artisan migrate
winpty works as long as you don't specify volumes to be mounted such as .:/mountpoint or ${pwd}:/mountpoint
The best workaround I have found is to use the git-bash plugin inside Visual Code Studio and use the terminal to start and stop containers or docker-compose.
For those using Pyinvoke see this documentation which I'll syndicate here in case the link dies:
99% of the time, adding pty=True to your run call will make things work as you were expecting. Read on for why this is (and why pty=True is not the default).
Command-line programs often change behavior depending on whether a controlling terminal is present; a common example is the use or disuse of colored output. When the recipient of your output is a human at a terminal, you may want to use color, tailor line length to match terminal width, etc.
Conversely, when your output is being sent to another program (shell pipe, CI server, file, etc) color escape codes and other terminal-specific behaviors can result in unwanted garbage.
Invoke’s use cases span both of the above - sometimes you only want data displayed directly, sometimes you only want to capture it as a string; often you want both. Because of this, there is no “correct” default behavior re: use of a pseudo-terminal - some large chunk of use cases will be inconvenienced either way.
For use cases which don’t care, direct invocation without a pseudo-terminal is faster & cleaner, so it is the default.
Instead of using -it use --tty
So your docker run should look like this:
docker run -v $PWD:/foobar --tty cloudfoundry/cflinuxfs2 /foobar/script.sh
use only -i flag than -it flag. which can help you to see what going on inside container.
docker exec -i $USER bash <<EOF
apt install nano -y
EOF
you might see the warning but it shows you output on the terminal inside docker.
Eval command does not exist in Windows.
The Docker for Windows tutorial step 6 says to run this command:
C:\Users\mary> eval "$(docker-machine env my-default)"
Is this a mistake in the tutorial or did I not install something correctly?
I can run this command just fine from Git Bash but I'm curious why the Docker tutorial says to run this command from the Windows command prompt.
Here is the link to the tutorial
https://docs.docker.com/v1.8/installation/windows/#using-docker-from-windows-command-line-prompt-cmd-exe
You can only run it from a bash indeed.
(like the git bash: C:\path\to\PortableGit-2.6.3-64-bit\git-bash.exe)
Or you can run it from a regular CMD, without the eval:
docker-machine env my-default
Run below commands to configure your shell/cmd terminal
docker-machine env --shell cmd my-default
FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd my-default') DO %i
After successfully running the above commands you can run any docker command from the shell/cmd terminal.
I use the cmder console emulator. For the most part, I followed the docker docs for setting up from the windows 10 command prompt, except for the eval statement. When I attempted to run the eval statement described in the docs, I was prompted to run a different command instead (below), and it successfully activated my machine. MYMACHINEHERE should be the name of the machine you will have already created in an earlier step.
#FOR /f "tokens=*" %i IN ('docker-machine env MYMACHINEHERE') DO #%i
For me it was just run
docker-machine env my-default
or (depending on witch tutorial step you are)
docker-machine env -u
Then copy-paste and run the command provided as the last line of the output to configure your shell.
eval is not required in windows. You can directly run without eval as following on cmd or powershell.
docker-machine env my-default