Docker in Windows is mounting files as directories - docker

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.

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: Mounted directory doesn't have files

I'm trying to mount a directory along with all of it's file contents. But it seems to only mount the directory without the contents:
> ls ~/test_dir
testfile
> docker run -it --rm --entrypoint bash -v ~/test_dir/:/test_dir:ro my_image:latest
bash-4.2# cd test_dir
bash-4.2# ls -a
. ..
bash-4.2#
I'm using Oracle Linux 7.9 terminal
Docker version 20.10.9

nextcloudpi in docker: Cannot use mounted external storage

Recently I installed nextcloudpi in docker with
sudo docker run -d -p 4443:4443 -p 443:443 -p 80:80 -v /home/user/storage/nextcloud:/data --name nextcloudpi ownyourbits/nextcloudpi-armhf <ip-adress-of-pi>
the folder /home/user/storage is a mounted external storage (following this tutorial https://www.techjunkie.com/build-nas-raspberry-pi-linux/)
It get me the error:
Running nc-init
Setting up a clean Nextcloud instance... wait until message 'NC init done'
Setting up database...
Setting up Nextcloud...
Console has to be executed with the user that owns the file config/config.php
Current user: www-data
Owner of config.php: root
Try adding 'sudo -u root ' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u root' to the docker command (without the single quotes)
I tried
sudo docker run -d -p 4443:4443 -p 443:443 -p 80:80 -v /home/user:/data --name nextcloudpi ownyourbits/nextcloudpi-armhf <ip-adress-of-pi>
and everythink workes well as far as I can tell. I can load the nextcloudpi config UI as well as the nextcloud GUI.
I have tried some chown and chmod for the /home/user/storage folder, without any succes.
How can i use the external storage as directory of the nextcloud?

pending when starting a container on remote host

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?

How to mount data directory?

I am not able to start percona mysql dockerized instance if I try to mount the data directory like this:
docker run --name percona57f -p 3384:3306 -v /my/custom3384:/etc/mysql/conf.d -v /storage/data3384:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=india3384 -e INIT_TOKUDB=1 -d percona/percona-server:5.7
The error is as shown below:
[ERROR] --initialize specified but the data directory exists and is not writable. Aborting.
[ERROR] Aborting
The command will work if I do not include the data directory like this...
docker run --name percona57g -p 3384:3306 -v /my/custom3384:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=india3384 -e INIT_TOKUDB=1 -d percona/percona-server:5.7
But it is very important for me to mount the data directory on host machine. Any way to enable this -v /storage/data3384:/var/lib/mysql
Run this command before docker run:
chown 1001 /my/custom3384
This is the UID for the mysql user, as shown in the Dockerfile for the percona image:
https://github.com/percona/percona-docker/blob/master/percona-server/Dockerfile
RUN useradd -u 1001 -r -g 0 -s /sbin/nologin \
-c "Default Application User" mysql

Resources