stdin is not a tty with Jenkins - docker

I have Jenkins installed locally on my laptop running windows 10. I spin up a Linux container running SQL Server, however when I attempt to run the following:
winpty docker exec -it SQLLinuxnull sudo /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P P#ssword1 -Q 'EXEC sp_configure '\''clr enabled'\'', 1;'
I get:
stdin is not a tty
When I run the docker exec command from a powershell session it completes without any issues. Trawling this site pulls up answer suggesting that this might be something to do with whatever account is being used in the Linux container requiring the ability to execute sudo and that I should alter the /etc/sudoers file, the problem being is that I do not have an /etc/sudoers file, according to uname -a this is the version of Linux the container is based on (not that its base is the official Microsoft SQL server in Linux image):
# uname -a
Linux f9509a952eae 4.9.49-moby #1 SMP Wed Sep 27 00:36:29 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Can someone confirm that this is a sudoers related issue.

docker exec -it
...requires that it be run in a context with a TTY available. If you can avoid needing stdin or a terminal later in the program's execution (for example, having /etc/sudoers inside the container configured with the RequireTTY option disabled), you should be able to simply remove the -it flags.

Related

How to execute multiple commands in a Docker container and leave the shell session open?

I have a running Docker container and need to start and interactive shell session inside the container and execute multiple commands inside before this.
How can I do that?
I tried
docker exec -it foo bash < my_commands_to_exexute_inside_the_container.sh
and
docker run foo bash -c "echo Foo;echo Bar"
But none of this works. The first one does not execute the commands from the script and the second one does this, but closes the terminal session.
Any idea?
Btw: The commands should come from outside the container. There is not file in the container with those commands.
Edit:
The following does almost exactly what I want it. The only catch is that the first command closes the shell and the second command opens it again. This causes me to lose environment variables.
docker exec -i foo bash < "cli.sh"
docker exec -it foo bash
Is there any way to achieve this behavior without closing the shell in between?
Drop the -t in your first command (you're running a script, not interacting with the shell prompt manually, so you don't need to allocate a TTY):
docker exec -i foo bash < my_commands_to_exexute_inside_the_container.sh
For example, if I start up a Fedora container:
docker run -d --name shell fedora:34 sleep inf
And I have a file mycommands.sh with the following content:
echo "The time is $(date)"
echo "This system is: $(uname -a)"
I can execute that shell in the container like this:
$ docker exec -i shell bash < mycommands.sh
The time is Sat Jul 31 12:37:59 UTC 2021
This system is: Linux 50715db46e9b 5.12.14-300.fc34.x86_64 #1 SMP Wed Jun 30 18:30:21 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
What about this?
docker run -it alpine sh -c "pwd;date;sh"

JProfiler inside Docker container: The JVM you are trying to attach to is running with a different user account

I am trying to run JProfiler inside my Docker container which is deploying my Java/Springboot application. By following the instructions provided here, I added this to my Dockerfile:
RUN wget http://download-keycdn.ej-technologies.com/jprofiler/jprofiler_linux_11_0.tar.gz -P /tmp/ &&\
tar -xzf /tmp/jprofiler_linux_11_0.tar.gz -C /usr/local &&\
rm /tmp/jprofiler_linux_11_0.tar.gz
ENV JPAGENT_PATH="-agentpath:/usr/local/jprofiler11.0/bin/linux-x64/libjprofilerti.so=nowait"
EXPOSE 8849
And then I enter the container to run the following inside /usr/local/jprofiler11.0:
bin/jpenable --gui --port=8849
which responds with the following error:
ERROR: The agent could not be loaded:
The JVM you are trying to attach to is running with a different user account.
Please run this tool with
sudo -u app jpenable
I am finding this error hard to understand because if I do a ps I get
PID USER TIME COMMAND
16 app 6:57 java -jar myRunningApp
And whoami confirms that I am user app. I also tried entering the container as root and the result is the same. Anyway, I am unable to run sudo -u app jpenable because I get bash: sudo: command not found, not sure if relevant. Running uname -a:
Linux 9cdef7df689d 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019 x86_64 Linux
Does anybody know what I am missing? Thank you for your help

How do you block console, root or other users, access to a docker container?

I tried installing puppet and changing the root user's shell to '/sbin/nologin' but I can still get right into the console?
It is a centOS 7 container.
Is Docker using a socket for the connection? Could I use selinux to block the socket? If I do I fear that I will also disable docker from being able to communicate with the container at all? I have been reading through Docker Security articles but have not found a good solution.
My end goal is for the container to be an ephemeral 'black box' when it comes up. My particular user case is a local web app, so no console access will be required.
You could try to remove all terminal commands (bash, sh, and so on) from the container:
docker exec [container-id] -it /bin/rm -R /bin/*
At that point you will not be able to use docker exec [container-id] -it bash to get a console to the container.
If you want to be more gentle about it you can only remove the shells you have (and leave all the other commands available (like the rm command):
docker exec [container-id] -it /bin/rm -R /bin/bash
docker exec [container-id] -it /bin/rm -R /bin/sh
... and so on

mysqld service is not starting on docker run

I am using the below command in the dockerfile to automatically start mysql on docker run:
ENTRYPOINT service mysql start && bash
The above command is working fine in some system but not in all. I also have tried the below command but still facing the same issue.
EXPOSE 3306
CMD /etc/init.d/mysql start && \
/bin/bash
I am getting the below error in some system:
* Starting MySQL database server mysqld [fail]
So can anyone please help me solve this issue. So that my docker container can run on all type of system where docker can be installed.
First, it depends on your exact docker run command.
As commented here, you approach works with docker run -itd ...
Second, it depends on the host, which should be compatible with docker execution (ie, its kernel should be the right architecture, 64bits not 32, recent enough...)
The OP adds:
I am using docker run -it docker_image_name command to run the docker image and second system i.e. Linux corona2 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux its not working.
I have used 1.8.3 version to build my image and.
is it because of the community edition version as ce is written with 18.03.1-ce.
Then yes: make sure to use the same docker version for building and running (on both servers)

docker error: /var/run/docker.sock: no such file or directory

I am new to docker. I have a shell script that loads data into impala and I want a docker file that runs builds an image and run the container.
I am on mac, installed boot2docker and have the DOCKER_HOST env set up.
bash-3.2$ docker info
Containers: 0
Images: 0
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Dirs: 0
Execution Driver: native-0.2
Kernel Version: 3.15.3-tinycore64
Debug mode (server): true
Debug mode (client): false
Fds: 10
Goroutines: 10
EventsListeners: 0
Init Path: /usr/local/bin/docker
Sockets: [unix:///var/run/docker.sock tcp://0.0.0.0:2375]
I am trying to just installed a pre-built image using:
sudo docker pull busybox
I get this error:
sudo docker pull busybox
2014/08/18 17:56:19 Post http:///var/run/docker.sock/images/create?fromImage=busybox&tag=: dial unix /var/run/docker.sock: no such file or directory
Is something wrong with my docker setup?
When I do a docker pull busybox, It pulls the image and download is complete.
bash-3.2$ docker pull busybox
Pulling repository busybox
a9eb17255234: Download complete
fd5373b3d938: Download complete
d200959a3e91: Download complete
37fca75d01ff: Download complete
511136ea3c5a: Download complete
42eed7f1bf2a: Download complete
c120b7cab0b0: Download complete
f06b02872d52: Download complete
120e218dd395: Download complete
1f5049b3536e: Download complete
bash-3.2$ docker run busybox /bin/echo Hello Doctor
Hello Doctor
Am I missing something?
You don't need to run any docker commands as sudo when you're using boot2docker as every command passed into the boot2docker VM runs as root by default.
You're seeing the error when you're running as sudo because sudo doesn't have the DOCKER_HOST env set, only your user does.
You can confirm this by doing a:
$ env
Then a
$ sudo env
And looking for DOCKER_HOST in each output.
As for having a docker file that runs your script, something like this might work for you:
Dockerfile
FROM busybox
# Copy your script into the docker image
ADD /path/to/your/script.sh /usr/local/bin/script.sh
# Run your script
CMD /usr/local/bin/script.sh
Then you can run:
docker build -t your-image-name:your-tag .
This will build your docker image, which you can see by doing a:
docker images
Then, to run your container, you can do a:
docker run your-image-name:your-tag
This run command will start a container from the image you created with your Dockerfile and your build command and then it will finish once your script.sh has finished executing.
You can quickly setup your environment using shellinit
At your command prompt execute:
$(boot2docker shellinit)
That will populate and export the environment variables and initialize other features.
docker pull will fail if docker service is not running. Make sure it is running by
:~$ ps aux | grep docker
root 18745 1.7 0.9 284104 13976 ? Ssl 21:19 0:01 /usr/bin/docker -d
If it is not running, you can start it by
sudo service docker start
For Ubuntu 15 and above use
sudo systemctl start docker
On my MAC when I start boot2docker-vm on the terminal using
boot2docker start
I see the following
To connect the Docker client to the Docker daemon, please set:
export DOCKER_CERT_PATH=<my things>
export DOCKER_TLS_VERIFY=1
export DOCKER_HOST=tcp://<ip>:2376
After setting these environment variables I was able to run the build without the problem.
Update [2016-04-28] If you are using a the recent versions of docker you can do
eval $(docker-machine env) will set the environment
(docker-machine env will print the export statements)
I also got this error. Though, I did not use boot2docker but just installed "plain" docker on Ubuntu (see https://docs.docker.com/installation/ubuntulinux/).
I got the error ("dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?") because the docker daemon was not running, yet.
On Ubuntu, you need to start the service:
sudo service docker start
See also http://blog.arungupta.me/resolve-dial-unix-docker-sock-error-techtip64
For boot2docker on Windows, after seeing:
FATA[0000] Get http:///var/run/docker.sock/v1.18/version:
dial unix /var/run/docker.sock: no such file or directory.
Are you trying to connect to a TLS-enabled daemon without TLS?
All I did was:
boot2docker start
boot2docker shellinit
That generated:
export DOCKER_CERT_PATH=C:\Users\vonc\.boot2docker\certs\boot2docker-vm
export DOCKER_TLS_VERIFY=1
export DOCKER_HOST=tcp://192.168.59.103:2376
Finally:
boot2docker ssh
And docker works again
In Linux, first of all execute sudo service docker start in terminal.
If you're using CentOS 7, and you've installed Docker via yum, don't forget to run:
$ sudo systemctl start docker
$ sudo systemctl enable docker
This will start the server, as well as re-start it automatically on boot.
To setup your environment and to keep it for the future sessions you can do:
echo 'export DOCKER_HOST="tcp://$(boot2docker ip 2>/dev/null):2375";' >> ~/.bashrc
Then:
source ~/.bashrc
And your environment will be setup in every session
The first /var/run/docker.sock refers to the same path in your boot2docker virtual machine. Correcly write for windows /var/run/docker.sock
You, maybe the not the OP, but someone may have a directory called /var/run/docker.sock/ already due to how many times you hack and slash to get things right with docker (especially noobs). Delete that directory and try again.
This helped me on my way to getting it to work on Centos 7.
I have installed the docker using offline method and post server restart docker is not running.
So, I executed the below command it worked for me!
/usr/bin/dockerd > /dev/null
run the following commands, OS = CentOS / RHLE / Amazon Linux, etc.
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
chmod 777 /var/run/docker.sock

Resources