| Products > Embedded Computing |
| hello world for linux in C++ |
| << < (30/30) |
| brucehoult:
You can get a 100% virgin Ubuntu any time by typing: --- Code: ---docker run -it ubuntu --- End code --- You'll find that all you need to add to your instructions is to first do "apt update". No "sudo" needed because you're root by default. Of course you do ned to have docker installed -- which you should. Very very handy software. (or an alternative) |
| Karel:
--- Code: ---docker run -it --entrypoint "/bin/bash" ubuntu:latest --- End code --- 8) |
| westfw:
--- Quote ---you do ned to have docker installed --- End quote --- I haven't looked at docker. Is having an extra layer of virtualization an issue? I dunno if I have enough RAM (or allocated disk) to allocate my ubuntu VM enough RAM to run another VM... |
| brucehoult:
--- Quote from: westfw on October 15, 2024, 10:43:35 pm --- --- Quote ---you do ned to have docker installed --- End quote --- I haven't looked at docker. Is having an extra layer of virtualization an issue? I dunno if I have enough RAM (or allocated disk) to allocate my ubuntu VM enough RAM to run another VM... --- End quote --- Assuming you're using Linux and the docker images you're using are for the same ISA as your computer then it's not a VM it's just essentially managing a chroot. The default x86_64 Ubuntu image is 78 MB. Doing apt update && apt install g++ and then committing that container as a new image (eg called "cpp") gives a 405 MB image. It doesn't have any text editor, but it's otherwise enough to write and run C++. Programs you run in the container use host OS RAM exactly the same as any other program. --- Code: ---bruce@i9:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE cpp latest b5fd00408694 11 minutes ago 405MB ubuntu latest dc4c1391d370 5 days ago 78.1MB bruce@i9:~$ docker run -it cpp root@30a089efa54f:/# cat >hello.cpp #include <iostream> int main(){std::cout << "Hello!" << std::endl; return 0;} root@30a089efa54f:/# g++ hello.cpp -o hello root@30a089efa54f:/# ./hello Hello! root@30a089efa54f:/# exit --- End code --- You can copy the program you built in the container into your normal OS and run it there: --- Code: ---bruce@i9:~$ docker cp 30a089efa54f:hello . Successfully copied 18.4kB to /home/bruce/. bruce@i9:~$ ./hello Hello! bruce@i9:~$ --- End code --- Once you have your image with g++ installed in it, containers that you create from it (e.g. 30a089efa54f here) are only the size of the files you added to them, so 30a089efa54f is 16.6 KB in size on disk. Really a very convenient way to keep environments for different OSes or different versions of tools etc separate, with very low overhead in disk space, RAM, and execution time. |
| ejeffrey:
Docker containers don't take reserved memory like a virtual machine. The container processes are running in the host kernel, just with a different view of the filesystem and other resources. A basic container doesn't run any daemons or even it's own init process: it's really just the memory image of the program running. They do usually have their own filesystem image which takes space. As Bruce explained that doesn't have to be huge for a simple build environment. That said, depending on how you use it old images can accumulate and need to be cleaned up occasionally. I use docker for running some xilinx tools and cadence tools that need a very particular OS version. It can definitely br a bit awkward at times but it's incredibly useful. |
| Navigation |
| Message Index |
| Previous page |