Just started using Docker and have some questions regarding linux containers.
How can I run Ubuntu images on a Debian host? Or it is just a name of image called 'Ubuntu' that actually use Debian environment?
# cat /proc/version
Linux version 3.16.0-0.bpo.4-amd64 (debian-kernel#lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Debian 3.16.7-ckt2-1~bpo70+1 (2014-12-08)
# docker run -i -t ubuntu
root#bcade5ce3b94:/# cat /proc/version
Linux version 3.16.0-0.bpo.4-amd64 (debian-kernel#lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Debian 3.16.7-ckt2-1~bpo70+1 (2014-12-08)
What about the filesystem? Does it use the same installed components or a new fs architecture that just depends on the kernel?
Maybe there is some good articles about the subject you can share.
In docker all images use the same kernel - that is why overhead is minimal - virtualization layer is very thin. All files in ubuntu image from ubuntu, but any image will give you the same output of uname -a, as it is the same kernel.
$ docker run --rm -ti ubuntu
root#318f07af2ca7:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"
You don't see host filesystem inside of container unless you will map some directory. The idea of container that it is running in the same way on any host - doesn't matter what installed there - you need only docker.
Related
This question already has answers here:
$(uname -a) returning the same in docker host or any docker container
(2 answers)
Closed 1 year ago.
I am learning docker basics. I created a simple image
FROM alpine
RUN apk add --update redis
CMD ["redis-server"]
I started the container and logged in using
docker exec -it c57389dc94f5 sh
From the shell prompt, if I execute
more /etc/alpine-release
I get 3.14.2.
If I execute
more /proc/version
I get
Linux version 5.4.0-84-generic (buildd#lgw01-amd64-050) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021
Why am I getting Ubuntu when the image uses Alpine?
/cat/proc give you the version of the OS which hosts the docker container, and not the docker image version. Remember that docker is not a virtual machine, but a bunch of isolated processes, named container, running on top of the hosting OS (and so, by its own kernel).
I guess that you are using docker on Ubuntu. Is it right?
Please refer to official docker containers architecture.
I am new to docker.
I installed wsland running wsl2 (with Ubuntu) in windows 11 and Docker Desktop to play with docker.
I am curious if there is any difference to run docker command such as docker build between in cmd or in wsl mode?
wsl mode means: I enter wsl before running anything in the cmd.
Hope my question is clear.
If you've installed native Docker packages inside Ubuntu (e.g. with apt) then Docker is unavailable in the Windows host so you can't even run commands from there.
If you've installed Docker Desktop on Windows (the recommended setup) then you're effectively getting integration between both OSes so it doesn't really matter which environment you use. In fact the Linux binaries are wrappers provided by the bundle:
$ ls -al $(which docker)
lrwxrwxrwx 1 root root 48 Aug 23 10:40 /usr/bin/docker -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker
Exactly the same problem as Ubuntu WSL with docker could not be found
$ docker
The command 'docker' could not be found in this WSL 1 distro.
We recommend to convert this distro to WSL 2 and activate
the WSL integration in Docker Desktop settings.
See https://docs.docker.com/docker-for-windows/wsl/ for details.
But my requirement is different -- I want to
stick with WSL1 (for reasons beyond this topic)
and use Docker for Windows as-is
I.e., I have WSL1 and Docker for Windows installed parallel to each other. This is my current info:
C:> ver
Microsoft Windows [Version 10.0.18363.1379]
C:> wsl -l -v
NAME STATE VERSION
* Debian Running 1
I don't see integration in "Resources -> WSL Integration", and I don't have WSL2 backend enabled in Docker Desktop settings.
Just that I'm getting the above problem -- my docker works anywhere, in CMD, Powershell, git-bash, etc, just not in my WSL.
All solutions that I found are to install Docker for Windows within WSL1 or WSL2, but I want to keep everything as is -- WSL and Docker for Windows installed parallel to each other.
Any solution for that?
The command 'docker' could not be found in this WSL 1 distro.
We recommend to convert this distro to WSL 2 and activate
the WSL integration in Docker Desktop settings.
This means in WSL2, it has a real linux kernel which is required to install docker daemon, then in docker-desktop you could have chance to set docker daemon in WSL2. Otherwise, the docker daemon is running in Hyper-V machine. But, if you stick in WSL1, no chance to run docker-daemon in WSL, so the only option is running docker daemon in Hyper-V machine.
Although above is the fact, still we have chance to let you operate docker ps, docker pull etc. in WSL1 bash just like you operate through CMD, Powershell, git-bash, that is allow Docker to accept requests from remote hosts.
For your case, the steps maybe next:
1. Expose docker daemon in docker desktop settings as next, then click Apply & Restart:
2. Install standalone docker client in WSL1:
$ wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz
$ tar zxvf docker-20.10.5.tgz
$ cd docker
3. Set default docker daemon:
$ export DOCKER_HOST=tcp://localhost:2375
4. Verify docker client command:
$ ./docker info
Just FTA, this is the quick hacky workaround that I found, while trying to solve it myself
Change the C:\Program Files\Docker\Docker\resources\bin\docker file to
#!/usr/bin/env sh
#
# Copyright (c) Docker Inc.
binary=$(basename "$0")
"$binary.exe" "$#"
Then docker can work anywhere now, in CMD, Powershell, git-bash, and as well as WSL1.
Note that this hacky workaround is specially for the situation described in OP, might not work for anything else.
I ran the same issue with Ubuntu 20 Distro when trying to use Docker. Below are steps i followed to resole it:
1- I went to microsoft Store and downloaded a recent distro version of the distro, that was Ubuntu 22.04
2- On powershell as admin, i ran the command wsl -l -v to make sure i have the new version
PS C:\WINDOWS\system32> wsl -l -v
NAME STATE VERSION
* Ubuntu Stopped 1
Ubuntu-22.04 Stopped 2
docker-desktop-data Stopped 2
docker-desktop Stopped 2
3- i ran the command: wsl --set-default Ubuntu-22.04 to use wsl 2
I wan now able to use Docker on WSL 2
I'm just starting docker.
According to some articles, the most significant difference of docker from VM is that it doesn't run on an emulated OS but on the host kernel.
However, when I run the nginx image on my Mac:
$ docker run -d nginx
a88142a23cb4e1900093ee4a27303f7d80adb0305e4008203829a84ae29ca4f2
$ docker exec -it a88142a23cb4e1900093ee4a27303f7d80adb0305e4008203829a84ae29ca4f2 bash
root#a88142a23cb4:/# cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root#a88142a23cb4:/#
So for me, it seems like this container actually runs Debian, and nginx on top of it.
Now I'm totally confused. Can somebody explain this output?
Docker use a base image to start which generally a OS image(Not actually OS. It does not have a kernel). It provides a file system and necessary library to run your application.
For more details, see this answer: https://stackoverflow.com/a/53049134/7695859
I just installed a brand new Ubuntu Server 14.04.2 LTS and also installed docker to run containers. I am facing some problems with it. A container will be used to run Jenkins and some of its jobs runs scripts to install Android NDK/SDK. These scripts are checking for the platform of the current machine using uname -p command. This command runs well on the host machine but it returns unknown in containers as follows:
lemonade#olympus:/$ docker info
Containers: 14
Images: 171
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Dirs: 199
Execution Driver: native-0.2
Kernel Version: 3.16.0-38-generic
WARNING: No swap limit support
lemonade#olympus:/$ uname -a
Linux olympus 3.16.0-38-generic #52~14.04.1-Ubuntu SMP Fri May 8 09:43:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
lemonade#olympus:/$ uname -p
x86_64
lemonade#olympus:/$ docker run -ti java:7 /bin/bash
root#c6cdbb8a64fb:/# uname -p
unknown
root#c6cdbb8a64fb:/# uname -a
Linux c6cdbb8a64fb 3.16.0-38-generic #52~14.04.1-Ubuntu SMP Fri May 8 09:43:57 UTC 2015 x86_64 GNU/Linux
Does anyone knows why are the containers returning this? Some scripts (which are not coded by us) use this, as well as a lot of makefiles.
Thanks!
I don't know the exact reason why uname -p fail with the java:7 docker image but it seems to be due to the docker debian image. With the ubuntu docker image, everything is fine.
$ docker run debian uname -p
unknown
$ docker run ubuntu uname -p
x86_64
If you look at the Dockerfile dependencies for the java:7 docker image you find out the following: java:7→buildpack-deps:jessie-scm→buildpack-deps:jessie-curl→debian:jessie
The only thing that breaks the uname -p is the dependency on debian:jessie. What could do is to build your own java:7 docker image, but making it depend on ubuntu instead of debian.
For that you would have to come up with a Dockerfile which is a merge of the ones used to make the java:7 image.
uname -p seems to be set to unknown for a lot of linux distributions.
Though you don't control those scripts and make files you might want to submit bug reports upstream recommending they change their code to use uname -m instead if they are trying to detect x86_64, armv7l, armv6l, etc.