Docker container not mounting volume properly - linux

I have the following directory:
.
└── wordpress
└── important-file.txt
1 directory, 1 files
My problem is that when I run the command below on my local WSL / Ubuntu:
$ docker run -it --rm -v "$(pwd)"/wordpress:/var/www/html php:7.3-fpm-alpine /bin/sh
I was expecting to find file: important-file.txt inside directory: /var/www/html, but the directory was empty.
I tried this on two different local computers and the result was the same. So, if you try it, probably you will get the same result.
In the other hand, if I run the same command on a Digital Ocean droplet the file is there.
Local WSL / Ubuntu system:
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
Digital Ocean droplet
# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.5 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.5 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
The file sharing of my Docker Desktop looks like:
Any idea on why I don't get that file on my local WSL / Ubuntu system?

I found the solution here:
https://github.com/docker/for-win/issues/3385#issuecomment-533279510
Specifically what I did was:
Give: docker-users full control over the directory I want to mount:
On the Windows console, run the command:
> icacls wordpress /q /c /t /grant docker-users:F
Restart the service: LxssManager:
Close and ReOpen the WSL / Ubuntu.
Try again:
That did the trick.

Related

systemctl doesnt work in Ubuntu 22.04 container

$ docker run -it --name systemd-tutorial ubuntu
root#306c0deb6960:~# systemctl
bash: systemctl: command not found
why??
The systemctl utility, which is available by default in Ubuntu, can be used to list services in Ubuntu 22.04 using the command “systemctl –no-pager”.
my version:
root#306c0deb6960:~# cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"
...
why?
Containers, typically used for single -service jobs, typically come without the full systemd suite of service management, which would have trouble running without access to the system dbus, anyway. So, this is kind of expected.

How to find out which Linux is installed inside docker image?

I am new to docker and this is just a fascinating tool. However, I can't understand one thing about it. Simple Dockerfile usually begins with OS name and version, like:
FROM ubuntu:xenial
....
But which Linux OS will be used for Dockerfile like
FROM perl
....
or
FROM python:3.6
....
Of course I can find this out by running a container from this image and printing out the OS info, like:
docker run -it --rm perl bash
# cat /etc/*-release
or
docker run -it --rm python:3.6 bash
# cat /etc/*-release
BTW, In both cases the OS is "Debian GNU/Linux 10 (buster)".
So, my questions are:
How do I find out which OS will be run for a specific docker image without actually creating a docker container from it (the docker inspect command does not provide this info: docker inspect perl | grep -i Debian)
How do I change the OS type for existing docker image. For example, I have an image that uses Ubuntu 14.04, and I want to change it to Ubuntu 18.04..
Thank you for your help:)
A docker image doesn't need an OS. There's a possibility of extending the scratch image which is purposely empty and the container may only contain one binary or some volume.
Having an entire OS is possible but also misleading: The host shares its kernel with the container. (This is not a virtual machine.)
That means that no matter what "OS" you are running, the same kernel in the container is found:
Both:
docker run --rm -it python:3.6 uname -a
docker run --rm -it python:3.6-alpine uname -a
will report the same kernel of your host machine.
So you have to look into different ways:
docker run --rm -it python:3.6 cat /etc/os-release
or
lsb_release -sirc
or for Cent OS:
cat /etc/issue
In stead of scratch, a lot of images are also alpine-based to avoid the size overhead. An ubuntu base image can easily have 500MB fingerprint whereas alpine uses around 5MB; so I rather check for that as well.
Also avoid the trap of manually installing everything onto one Ubuntu image inside one big Dockerfile. Docker works best if each service is its own container that you link together. (For that check out docker-compose.)
In the end, you as an user shouldn't care about the OS of an image, but rather its size. Only as a developer of the Dockerfile is it relevant to know the OS and that you'll find out either by looking into the Dockerfile the image was built (if it's on docker hub you can read it there).
You basically have to look what was used to create your image an use the appropriate tools for the job. (Debian-based images use apt-get, alpine uses apk, and Fedora uses yum.)
How do I find out which OS will be run for a specific docker image without actually creating a docker container from it
The only way to determine what os is being used is as you have described: spawn a container and print the os information. There is no metadata that says "this image was build using <x>".
In many (but not all) situations, this information may not be especially important.
How do I change the OS type for existing docker image. For example, I have an image that uses Ubuntu 14.04, and I want to change it to Ubuntu 18.04..
If you have access to the Dockerfile used to build the image, you can of course change the base image (the image named in the FROM line) and build a new one, but you may find that this requires a number of other changes due to different software versions in your updated image.
You can use "docker cp" to extract the "/etc/os-release" file without starting the container:
$ docker pull ubuntu:latest
Status: Image is up to date for ubuntu:latest
$ docker create ubuntu:latest
2e5da8bf02312870acd0436e0cc4eb28fbcc998f766cd9639c37101f65739553
$ docker cp -L 2e5da8bf02312870acd0436e0cc4eb28fbcc998f766cd9639c37101f65739553:/etc/os-release .
$ docker rm 2e5da8bf02312870acd0436e0cc4eb28fbcc998f766cd9639c37101f65739553
$ cat ./os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
Note: I had to use "docker cp -L" because /etc/os-release is a symlink on ubuntu:latest.
Honestly, I find this to be a lot of trouble just to avoid starting the container, and it requires the "/etc/os-release" file to be present. If you're willing to (very) briefly run the container, I find this more convenient, and a little more robust. Note: it's very important to specify --entrypoint="", otherwise the container will start invoking its normal startup routine!
$ docker run --rm -i -a STDOUT --entrypoint="" \
ubuntu:latest sh -c 'head -n 1000 /etc/hostname /etc/*[Rr][Ee][Ll]*'
==> /etc/hostname <==
b243ff33e245
==> /etc/lsb-release <==
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"
==> /etc/os-release <==
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
Here's the same command against "alpine:latest":
docker run --rm -i -a STDOUT --entrypoint="" \
alpine:latest 'sh' '-c' 'head -n 1000 /etc/hostname /etc/*[Rr][Ee][Ll]*'
==> /etc/hostname <==
a8521c768aeb
==> /etc/alpine-release <==
3.13.4
==> /etc/os-release <==
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.13.4
PRETTY_NAME="Alpine Linux v3.13"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
Note: I add "/etc/hostname" to the list of files to "head" to make sure it finds 2 or more files, to ensure "head" to uses its "==> file <==" output style. Whereas if it only runs against a single file it doesn't print the filename.

Version of Ubuntu being used in a docker container

I'm trying to figure out the version of Ubuntu being used in a docker container.
This Verfiy the version of ubuntu running in a Docker container mentions cat /etc/lsb-release which gives:
cat: can't open '/etc/lsb-release': No such file or directory
and uname -r gives:
3.13.0-119-generic
FWIW, uname -a gives:
Linux <container id> 3.13.0-119-generic #166-Ubuntu SMP Wed May 3 12:18:55 UTC 2017 x86_64 Linux
Any ideas what version of Ubuntu it might be? Or how else I can find this out?
Try lsb-release -a or cat /etc/issue
Just docker history --no-trunc your_image will show, among other things the FROM ... line

How to install Neovim on a remote server as a non-sudoer?

If I am not a sudoer of a remote server, I am wondering whether it is possible for me to install Neovim. Here is the server release:
$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.4 LTS"
NAME="Ubuntu"
VERSION="14.04.4 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.4 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
This might be an overkill if you just wish to install a single programm, but you can use Junest to install most command line software without root. It uses an Arch-based Linux distribution inside your home folder.
Another way would be to build Neovim from source and set the prefix to a folder you have write access (Neovim wiki). But this would require your remote server to have all dependencies + CMake installed.

Installing files in Ubuntu

I need to download the NVIDIA CUDA tool kit. I am running on Ubuntu server, I don't know which one to download. I checked the ubuntu version, below is the output.
root#ubuserver3:/home/admin# uname -m && cat /etc/*release
i686
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.4 LTS"
NAME="Ubuntu"
VERSION="12.04.4 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.4 LTS)"
VERSION_ID="12.04"
The download link is this - https://developer.nvidia.com/cuda-downloads
Which one should I download? There are 2 files .run and .deb under 32 bit of Ubuntu 12.04. I have no idea.
They are both work, but there is a little difference.
For the deb package, you can use
$ sudo dpkg -i cuda_deb_file.deb
the .run package, just
$ chmod +x cuda_run_file.run
$ ./cuda_run_file.run
The first one install the file to /usr/bin/ /usr/include/ /usr/lib/, but
the second one need you specify the path before installation.

Resources