Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Docker 'From Scratch' which os will run

Tags:

docker

In docker hello-world example, base image is Scratch, so where the commands will execute, if i not mention any os in base image. Will it execute in host OS (my OS is mac) or Will it execute in docker software or Will creates any OS internally

If its executes in host os, then i will write mac commands (my host os is mac), now if i give that image to some one his os is windows, is it run ?

like image 418
trinath Avatar asked Nov 29 '18 15:11

trinath


2 Answers

The term “operating system” has gotten a little overloaded.

Docker containers always run on a Linux kernel (except for the case of native Windows containers). On a non-Linux system (e.g., a Mac) there is a Linux virtual machine, and containers always run on that VM. All containers share that “host” or VM kernel (and by default are prohibited from making changes that would affect the whole system).

“Operating system” can also imply a stack of libraries, utilities, and programs that run on top of the kernel. Docker lets you run an Ubuntu userspace, or an Alpine userspace, or some other userspace...or no userspace at all. There can be minor incompatibilities between these (if you use a couple of specific things in GNU libc; if you believe /bin/sh is always GNU bash; ...).

You usually don’t want FROM scratch. You get nothing, beyond a couple of bits like /proc and /dev that Docker supplies for you. You do not get, for example, a shell. It’s most useful if you have a statically-linked Linux binary and for whatever reason want to wrap it in a container (your application generally must be written in C, C++, or Go, and you need to take special steps to statically link it).

Docker can never cause commands to get run on the host (especially if there’s a VM layer involved), and if your program’s primary goal is interacting with host programs or reading and writing host files then you actively don’t want the isolation that Docker provides. A different packaging system will probably work better for you.

like image 98
David Maze Avatar answered Oct 10 '22 21:10

David Maze


The scratch image is used as a "container" of a binary executable. In the hello-world example,

FROM scratch
COPY hello /
CMD ["/hello"]

hello is a executable, built with gcc.

So if you intend to use scratch, you will have to compile your code, the architecture is dependent of where you want to launch it. For example, on a modern pc it will be amd64, on a raspberry pi, it will be arm*.

Quote: https://docs.docker.com/develop/develop-images/baseimages/#create-a-simple-parent-image-using-scratch

Note: Because Docker for Mac and Docker for Windows use a Linux VM, you need a Linux binary, rather than a Mac or Windows binary.

Back to your question, for mac window and linux Docker will execute the binary as in linux. You can't use any mac commands with scratch because it should be an executable inside.

like image 1
Siyu Avatar answered Oct 10 '22 19:10

Siyu