pending when starting a container on remote host - docker

I have already configured remote api for docker in my server.
$ ps -ef |grep dockerd
root 5191 1 0 5월08 ? 00:01:41 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:4243
When I run a container in a Jenkins container running in my server,
The container is pended after creating the container.
[Execute Shell]
export DOCKER_HOST=tcp://10.254.239.53:4243
docker run -it --rm ubuntu:18.04 ls
<--- pending and display nothing
The result of docker ps -a in my server
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
609198e3928d ubuntu:18.04 "ls" 8 seconds ago Created lucid_curran
When I execute the same command with "-d" option, it is ok. But useless.
[Execute Shell]
export DOCKER_HOST=tcp://10.254.239.53:4243
docker run -d ubuntu:18.04 ls
When I run the same command in my server, executed correctly.
$ docker run --rm -it ubuntu:18.04 ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
How do I fix this error?

Related

Can't change ownership of '/dev/gpiomem' in a docker container in RPi

I'm trying to run a simple docker container with a python base image to control the LEDs on my RPi4.
The Dockerfile compiles fine and I'm running it as follows:
docker run --rm -ti --privileged --device /dev/gpiomem:/dev/gpiomem -d led_blinker bash
Once inside the docker container I run a ls -l /dev/gpiomem and I get
root#ca1506d00cc5:/# ls -l /dev/gpiomem
crw-rw---- 1 nobody nogroup 246, 0 Dec 30 21:47 /dev/gpiomem
I try to do
root#ca1506d00cc5:/# chown root.root /dev/gpiomem
chown: changing ownership of 'dev/gpiomem': Operation not permitted
But when I run a whoami I get I'm the root user. What is that I'm missing?
PS. I have also added the flag --user root and got the same results.

Docker run maps volumes with user "nobody" of "nogroup"

So far I have not had this problem. I am running a container image in a remote workstation. Different than normal, this workstation is not connected to the internet and I had to initiate the docker deamon manually. (for reference)
After this to run the container I tried to do
docker run -it -t --rm --gpus all --env CUDA_VISIBLE_DEVICES -v "/mnt/disco/projects/ThisProject/:/home/ThisProject/" -w "/
home/ThisProject/" container_image:latest /bin/bash
When I do this I got into the container on folder /home/ThisProject with root user but I cannot ls here. I do cd .. and ls -l and I can see that the ThisProject folder has this
drwxrws--- 7 nobody nogroup 4096 Jul 21 07:30 ThisProject
As you can see the owner is "nobody"
What can I do to correct this?

How to pass a command to a docker container with PowerShell?

I would like to send a command to an already existing docker container.
I am forced to do it via powershell or CMD, git bash not giving the correct Windows path using pwd.
Functionnal example
$cur_path = $pwd.Path
$container_id = docker run -it -d --volume $cur_path\:/matmuttools saagie/python:3.5.2-1.3.1-centos
docker exec $container_id 'ls'
docker stop $container_id
docker rm $container_id
Gives the following output:
anaconda-post.log
bin
dev
etc
git-credential-manager-2.0.4.jar
home
lib
lib64
lost+found
matmuttools
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
Non functionnal example
However, when doing something more "complex", docker throws an error:
$cur_path = $pwd.Path
$container_id = docker run -it -d --volume $cur_path\:/matmuttools saagie/python:3.5.2-1.3.1-centos
docker exec $container_id 'ls /matmuttools'
docker stop $container_id
docker rm $container_id
Throws the following error:
OCI runtime exec failed: exec failed: container_linux.go:367: starting
container process caused: exec: "ls /matmuttools": stat ls
/matmuttools: no such file or directory: unknown
If I pass ls without quotes and without more argument (just ls), it runs in the container. If I pass ls without quotes and with arguments, it runs on the host.
Runs in the container:
docker exec $container_id ls
Runs on the host:
docker exec $container_id ls /
How do I properly send a command to execute to a docker container in powershell (or with CMD) ?
In git bash, to get the actual windows path, use:
pwd -W
Now that I do not need powershell anymore (I am pretty sure it was not a blocking thing, but anyway):
docker exec -it frosty_lamport bash -c "cd /matmuttools; ls"

How to docker exec -ti CONTAINER_NAME /bin/bash on deployed docker stack?

I have a deployed docker stack on AWS with swarm:
docker stack deploy --with-registry-auth -c docker-stack.yml pipeline
I want to get an interactive bash session into one of the containers defined in the docker-stack.yml, but the various docker exec -ti CONTAINER_NAME /bin/bash invocations that I have tried all fail.
What is the right method to derive a container name to be passed to:
docker exec -it CONTAINER_NAME /bin/bash
given that:
docker service ps pipeline_django
returns valid service information and:
docker stack ps pipeline
returns valid stack information.
None of the documented methods of deriving the container_name from these commands work when passed to the docker exec -it command. They all fail with:
Error response from daemon: No such container
I've tried the things listed here:
execute a command within docker swarm service
The other answers failed, because they no not extract the container it from the task. Swarm wraps a task object around a container:
taskid=$(docker service ps -q ${servicename} |head -1)
containerid=$(docker inspect -f '{{.Status.ContainerStatus.ContainerID}}' ${taskid})
docker exec -it ${containerid} "$*"
Of course, this will only take the first container in the list.
Here is an example on my local macOS.
$ docker stack ls
NAME SERVICES
gospot_web 1
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
qigx492p2lbe gospot_web_web global 1/1 gospot/gospot-web:0.1.20.g225306b *:80->80/tcp, *:443->443/tcp
You can use either container id or container name to access the container.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b3824a85d3c8 gospot/gospot-web:0.1.20.g225306b "nginx -g 'daemon of…" 2 hours ago Up 2 hours (healthy) 80/tcp, 443/tcp gospot_web_web.3cqcd1v22vaon517j7p5h1d9a.wrel676fcllssrm3151ymkse9
$ docker exec -it b3824a85d3c8 sh
/ # ls
bin etc lib mnt root sbin sys usr
dev home media proc run srv tmp var
/ #
$ docker exec -it
gospot_web_web.3cqcd1v22vaon517j7p5h1d9a.wrel676fcllssrm3151ymkse9 sh
/ # ls
bin dev etc home lib media mnt proc root run
sbin srv sys tmp usr var
/ #
If the target service name is unique enough, you can use the following one-liner.
$ docker exec -it $(docker ps | grep gospot_web_web | awk '{print $1}') sh
/ # ls
bin etc lib mnt root sbin sys usr
dev home media proc run srv tmp var
/ #
Hope this helps.
You can use below command and replace SERVICE_NAME with your service name:
docker exec -it \
$(docker stack ps pipeline| grep SERVICE_NAME | cut -d' ' -f1) /bin/bash
this command finds the container id of your service:
docker stack ps pipeline| grep SERVICE_NAME | cut -d' ' -f1

Docker in Windows is mounting files as directories

I'm trying to run this command in my Powershell:
docker run -u postgres --net host -v /`pwd`/file.sql://tmp/setup.sql --rm postgres:9.4 psql -h localhost -U postgres -f //tmp/setup.sql my_db;
which is giving me this error:
psql:/tmp/setup.sql:0: could not read from input file: Is a directory
I tried running a bash in that docker container via this command:
docker run -it -u postgres --net host -v /`pwd`/file.sql://tmp/setup.sql --rm postgres:9.4 bash
and then did a simple ls -l /tmp inside the docker tty, and it's showing that setup.sql file is actually a directory!
drwxr-xr-x 2 root root 40 Jan 13 08:39 setup.sql
How do I go about doing this? I've also tried the bash shell supplied by msysgit with the same results.

Resources