Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380... while using docker on Ubuntu WSL 2 - linux

I am following an already written guideline on running docker and Mariadb on VM. but I am using wsl ubuntu on windows.
(sudo) apt update
(sudo) apt upgrade
* Docker
(sudo) apt-get install docker.io
Portainer
(sudo) docker volume create portainer_data
(sudo) docker run --name portainer -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer --log-opt max-size=50m --log-opt max-file=5 -d --privileged -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v /path/on/host/data:/data portainer/portainer
MariaDB
(sudo) mkdir /mnt/raid/data/mariadb
(sudo) mkdir /mnt/raid/data/mariadb/storage
(sudo) touch /mnt/raid/data/mariadb/config.cnf
(sudo) nano /mnt/raid/data/mariadb/config.cnf
but I get an error whenever I run docker run --log-opt max-size=50m --log-opt max-file=5 --name mariadb -v /mnt/raid/data/mariadb/storage:/var/lib/mysql -v /mnt/raid/data/mariadb/config.cnf:/etc/mysql/my.cnf -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -d mariadb/server:latest
This is the error:
Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:75: mounting "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/e18d5bf9d7f9627840069cbdafadd22ec458ffe154082d3c685ed8b1a4f15eb2" to rootfs at "/etc/mysql/my.cnf" caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
I guess it might be an error with the mounting because I cannot locate the locations of the created path or the folder in the system.

Related

how to mount a disk partition in docker

I have the below sd card partition from sudo blkid
/dev/sdb1: PARTLABEL="uboot" PARTUUID="5e6c4af7-015f-46df-9426-d27fb38f1d87"
...
...
...
/dev/sdb8: UUID="5f38be2e-3d5d-4c42-8d66-8aa6edc3eede" BLOCK_SIZE="1024" TYPE="ext2" PARTLABEL="userdata" PARTUUID="dceeb110-7c3e-4973-b6ba-c60f8734c988"
/dev/sdb9: UUID="51e83a43-830f-48de-bcea-309a784ea35c" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="rootfs" PARTUUID="c58164a5-704a-4017-aeea-739a0941472f"
I am trying to mount /dev/sdb9 into a docker container so that I can reformat it and do other stuffs with it.
But I am not able to attach it as a volume in docker container.
This is what I've done:
docker volume create --driver=local --opt type=ext4 --opt device=/dev/disk/by-uuid/51e83a43-830f-48de-bcea-309a784ea35c my-vol
docker run <image id> -v my-vol:/my-vol -it bash
However, it came up with the error: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "-v": executable file not found in $PATH: unknown.
Any ideas how i can mount /dev/sdb9 into a docker container?
You need to change the order of your docker run command so that the options come before the image. Everything after the image is considered as args, you need to provide options such as volume before the image name. From the docker run docs https://docs.docker.com/engine/reference/commandline/container_run/:
docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]
$ docker run -it ubuntu -v $(pwd):/local
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "-v": executable file not found in $PATH: unknown.
$ docker run -it -v $(pwd):/local ubuntu
root#8fa69b8861d8:/#

Run docker inside docker as non root user

How can I run docker commands inside a docker container when the user is not root?
The reason behind this (running as non root) is that the (first) container creates some files on a mounted volume. If the user in the container is root then these files' owner is also root. If I run the container with the same user as on the host system then these files have the correct user and group.
docker run --rm -it -u $(id -u):$(id -g) -v /var/run/docker.sock:/var/run/docker.sock ubuntu /bin/bash
// inside container:
// assume docker binary is available
docker pull alpine
This will not work when run as a non root user giving following error:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/create?fromImage=alpine&tag=latest: dial unix /var/run/docker.sock: connect: permission denied
Docker:
docker run -it -u $(id -u):$(id -g) --group-add $(getent group docker | cut -d ':' -f 3) --rm -v /var/run/docker.sock:/var/run/docker.sock docker docker --version
For Docker Compose set group_add under your service and set the env variable:
export DOCKER_GROUP_ID=$(getent group docker | cut -d ':' -f 3);
services:
myservice:
image: docker
group_add:
- ${DOCKER_GROUP_ID}

Docker flag "--gpu" does not work without sudo command

I'm ubuntu user. I use the following docker image, tensorflow/tensorflow:nightly-gpu
If I try to run this command
$ docker run -it --rm --gpus all tensorflow/tensorflow:nightly-gpu bash
There's permission denied error.
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: Running hook #0:: error running hook: exit status 1, stdout: , stderr: nvidia-container-cli: mount error: open failed: /sys/fs/cgroup/devices/user.slice/devices.allow: permission denied: unknown.
Of course, I can run this command if I am using sudo, but I want to use gpu without sudo.
Is there any good solution? Any leads, please?
As your problem seems to be only when running "--gpu".
Add/update these two sections of /etc/nvidia-container-runtime/config.toml
[nvidia-container-cli]
no-cgroups = true
[nvidia-container-runtime]
debug = "/tmp/nvidia-container-runtime.log"
Source: https://github.com/containers/podman/issues/3659#issuecomment-543912380
If you can't use docker without sudo at all
If you are running in a Linux environment, you need to create a user for docker so you won't need to use sudo every time. Below are the steps to create:
$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ newgrp docker
Source: https://docs.docker.com/engine/install/linux-postinstall/

Docker Redis start with persistent storage using -v gives error (chown: changing ownership of '.': Permission denied)

I'm using following system version/spec for the docker-redis setup using default redis.conf.
Redhat version: 7.6 (Red Hat Enterprise Linux Server)
Redis Version: 5.0.4
Docker Version: 1.13.1, build b2f74b2/1.13.1
When I run following command it's working perfectly fine.
sudo docker run -d -v $PWD/redis.conf:/usr/local/etc/redis/redis.conf --name redis-persistance --net tyk -p 7070:6379 redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
I need to get redis data (which is in /data inside the container) to the host directory (/usr/local/etc/redis/data) (-v $PWD/data:/data). So when I run following command I'm getting the below error.
Note $PWD = /usr/local/etc/redis/
sudo docker run -d -v $PWD/redis.conf:/usr/local/etc/redis/redis.conf -v $PWD/data:/data --name redis-persistance --net tyk -p 7070:6379 redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
Error in docker logs:
journal: chown: changing ownership of '.': Permission denied
level=warning msg="05ce842f052e28566aed0e2eab32281138462cead771033790266ae145fce116 cleanup: failed to unmount secrets: invalid argument"
Also I tried changing the ownership of the data folder in the host to following as well. chown redis:redis data
drwxrwxrwx. 2 redis redis 6 May 3 07:11 data
Can someone help me out on this. Thanks.
First create a volume:
docker volume create redis_data
Check the volume is created (note the Mountpoint):
docker volume inspect redis_data
Then use this volume to start your container:
sudo docker run -d -v $PWD/redis.conf:/usr/local/etc/redis/redis.conf -v redis_data:/data --name redis-persistance --net tyk -p 7070:6379 redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
You can then check the contents of the "Mountpoint" that should be the redis data.

Docker container not showing volume mounted - Access issue

root#centdev01$ grep -e CMD -e RUN Dockerfile
RUN apt-get update
RUN apt-get -y install ruby ruby-dev build-essential redis-tools
RUN gem install --no-rdoc --no-ri sinatra json redis
RUN mkdir -p /opt/webapp
RUN chmod 777 /opt/webapp
CMD ["/opt/webapp/bin/webapp"]
root#centdev01$ docker build -t "alok87/sinatra" .
root#centdev01$ docker run -d -p 80 --name ubunsin10 -v $PWD/webapp:/opt/webapp alok87/sinatra
25ekgjalgjal25rkg
root#centdev01$ docker logs ubunsin10
/opt/webapp/bin/webapp: Permission Denied - /opt/webapp/bin/webapp ( Errno:EACCESS)
The issue is the volume is being mounted to the container but from the container it is not having any acces to the mounted volume. I can cd to /opt/webapp/bin but i can not ls /opt/webapp/bin.
Please suggest how it can be fixed. The host mount has all files having 777 permission.
Docker processes have the svirt_lxc_net_t default type. By default these processes are not allowed to access your content in /var, /root and /home.
You have specify a suitable type label for your host folder, to allow the container processes to access the content. You can do this by giving the $PWD/webapp folder the type label svirt_sandbox_file_t.
chcon -Rt svirt_sandbox_file_t $PWD/webapp
After this, you can access the folder from within the container. Read more about it in Dan Walsh's article - Bringing new security features to Docker

Resources