sickcodes / Docker-OSX

Run macOS VM in a Docker! Run near native OSX-KVM in Docker! X11 Forwarding! CI/CD for OS X Security Research! Docker mac Containers.
https://hub.docker.com/r/sickcodes/docker-osx
GNU General Public License v3.0
36.1k stars 1.78k forks source link

How to allocate more CPU cores and Memory to a docker image/container ? #500

Open heli-aviator opened 2 years ago

heli-aviator commented 2 years ago

Hi, I know this is not really an issue, but it's a user"me" issue, I'm running EndeavourOS latest,

I installed Monteray following the initial setup and then the docker run it command from the read me page, and it works really good, but I would like to allocate more resources to the image/container

I've tried following some of the examples but I just can't get it to work.

Let's say the i.e.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 123456789 sickcodes/docker-osx:monterey "/bin/bash -c 'sudo …" 2 days ago Exited (0) 23 hours ago gifted_pirate

I currently start the docker image with docker start -ai 12345679 how would I add the variables to give it 8cpu cores and 16gb ram? Eventually, when I can afford a 2nd GPU I would like to learn how to do GPU passthrough to that image as well.

It would be much appreciated if you could explain this to me in layman's terms, as I'm just starting to learn docker and VM's when you teach me how to do it I will make a YT video on my channel showing how to do it, because I'm sure I'm not the only one struggling with this stuff, in the beginning, I will give you full credit!

if any of these matters here are my system specs: MSI unify x570 MB Ryzen 3950X Radeon VII 32GB ram m.2 pcie gen 4 storage

imunique-ZJ commented 2 years ago

Hi, you can check this solution. Say you need 8cpu cores, you can add following parameters to your docker run command

-e EXTRA="-smp 8,sockets=1,cores=8,threads=1

// or if you prefer more threads
-e EXTRA="-smp 8,sockets=1,cores=4,threads=2

// or if you prefer more sockets
-e EXTRA="-smp 8,sockets=2,cores=2,threads=2

Since you have Ryzen 3950X, maybe you can use more cpu resources such as

-e EXTRA="-smp 16,sockets=1,cores=8,threads=2

And if you need 16gb ram, you can add this

-e RAM=16
heli-aviator commented 2 years ago

I've tried all the ways I can think of to implement that in my startup, but it does not seem to work.

Xhost -

start -ai 12345679 -e EXTRA="-smp 8,sockets=1,cores=8,threads=1" -e RMA=16

Xhost +

Any input on how to implement that the right way?

imunique-ZJ commented 2 years ago

I think you should declare how much resources you need when you create the container not when start. Here is my configuration

docker run -i \
  --name myMacOSX2 \
  --privileged \
  --device /dev/kvm \
  -e RAM=32 \
  -p 50922:10022 \
  -p 3001:3001 \
  -e "DISPLAY=${DISPLAY:-:0.0}" \
  -e EXTRA="-smp 8,sockets=1,cores=8,threads=1 -device virtio-serial-pci -device usb-host,hostbus=1,hostport=2.3 -monitor telnet::45454,server,nowait -nographic -serial null -spice disable-ticketing,port=3001" \
  -e GENERATE_UNIQUE=true \
  -e GENERATE_SPECIFIC=true \
  -e NOPICKER=true \
  -v "${PWD}/output.env:/env" \
  -v "${PWD}/mac_hdd_ng.img:/image" \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  sickcodes/docker-osx:naked
uforek commented 1 year ago

Is there a way to update the RAM and CPU AFTER creation? I already installed Ventura and it takes a while. I'd like to avoid doing that all over again.

imunique-ZJ commented 1 year ago

Not sure if it is possible

  1. docker export your image as xxx.tar
  2. docker load your xxx.tar
  3. docker run with updated resources allocation