Running Gui Apps Docker Mac

Running GUI apps with Docker I’ve been doing all of my real (paid) work on VMs / containers for a while now but when it comes to writing Java code for some projects for university I still need to move away from using vim and install some full blown IDE in order to be productive.

Running Gui Apps Docker Mac
  1. # Create the GUI User ##### ENV USERNAME guiuser RUN useradd -m $USERNAME && echo '$USERNAME:$USERNAME' chpasswd && usermod -shell /bin/bash $USERNAME && usermod -aG sudo $USERNAME && echo '$USERNAME ALL=(ALL) NOPASSWD:ALL' /etc/sudoers.d/$USERNAME && chmod 0440 /etc/sudoers.d/$USERNAME && # Replace 1000 with your user/group id usermod -uid 1000 $USERNAME && groupmod -gid 1000 $USERNAME # To run a GUI application, you need to do it from this user!
  2. I have read the guidelines to run GUI apps inside docker. But when it comes to Mac, all the guides rely on boot2docker or running docker inside a VM and forwarding the x11 using xquartz. Since we have docker for mac now, is it possible to forward the video and audio directly without using xquartz or vnc? From Jessie’s blog, in docker run command these are the parameters I am interested in.
  3. This is a short guide explaining how to run GUI applications from within Docker on Mac. This uses XQuartz to enable to set the DISPLAY variable within the container. Install XQuartz. You can install XQuartz using homebrew with brew cask install xquartz or directly from the website here.
  4. On a Mac you may find the following steps useful: Install XQuartz; Open it, goto preferences Security and check the option to allow connections from network clients.

Estimated reading time: 4 minutes

Welcome! We are excited that you want to learn Docker.

This page contains step-by-step instructions on how to get started with Docker. We also recommend the video walkthrough from Dockercon 2020.

The Docker Quickstart training module teaches you how to:

  1. Set up your Docker environment (on this page)

Docker concepts

Docker is a platform for developers and sysadmins to build, run, and shareapplications with containers. The use of containers to deploy applicationsis called containerization. Containers are not new, but their use for easilydeploying applications is.

Gui

Containerization is increasingly popular because containers are:

  • Flexible: Even the most complex applications can be containerized.
  • Lightweight: Containers leverage and share the host kernel,making them much more efficient in terms of system resources than virtual machines.
  • Portable: You can build locally, deploy to the cloud, and run anywhere.
  • Loosely coupled: Containers are highly self sufficient and encapsulated,allowing you to replace or upgrade one without disrupting others.
  • Scalable: You can increase and automatically distribute container replicas across a datacenter.
  • Secure: Containers apply aggressive constraints and isolations to processes without any configuration required on the part of the user.

Images and containers

Fundamentally, a container is nothing but a running process,with some added encapsulation features applied to it in order to keep it isolated from the host and from other containers.One of the most important aspects of container isolation is that each container interacts with its own private filesystem; this filesystem is provided by a Docker image.An image includes everything needed to run an application - the code or binary,runtimes, dependencies, and any other filesystem objects required.

Containers and virtual machines

A container runs natively on Linux and shares the kernel of the hostmachine with other containers. It runs a discrete process, taking no more memorythan any other executable, making it lightweight.

By contrast, a virtual machine (VM) runs a full-blown “guest” operatingsystem with virtual access to host resources through a hypervisor. In general,VMs incur a lot of overhead beyond what is being consumed by your application logic.

Set up your Docker environment

Download and install Docker Desktop

Docker Desktop is an easy-to-install application for your Mac or Windows environment that enables you to start coding and containerizing in minutes. Docker Desktop includes everything you need to build, run, and share containerized applications right from your machine.

Follow the instructions appropriate for your operating system to download and install Docker Desktop.

Test Docker version

After you’ve successfully installed Docker Desktop, open a terminal and run docker --version to check the version of Docker installed on your machine.

Test Docker installation

Docker Windows Gui Applications

  1. Test that your installation works by running the hello-world Docker image:

  2. Run docker image ls to list the hello-world image that you downloaded to your machine.

  3. List the hello-world container (spawned by the image) which exits after displaying its message. If it is still running, you do not need the --all option:

Conclusion

At this point, you’ve installed Docker Desktop on your development machine, and ran a quick test to ensure you are set up to build and run your first containerized application.

For information on how to build and run your first containerized application using Node.js, go to Build your Node.js image.

CLI references

Refer to the following topics for further documentation on all CLI commands used in this article:

get started, setup, orientation, quickstart, intro, concepts, containers, docker desktop

I’ve been doing all of my real (paid) work on VMs / containers for a while now but when it comes to writing Java code for some projects for university I stillneed to move away from using vim and install some full blown IDE in order to beproductive. This has been bothering me for quite some time but this week Iwas finally able put the pieces together to run NetBeans in a Docker container so that I can avoidinstalling a lot of Java stuff on my machine that I don’t use on a daily basis.

There are a few different options to run GUI applications inside a Dockercontainer like using SSH with X11 forwarding,or VNC but the simplest one that Ifigured out was to share my X11 socket with the container and use it directly.

The idea is pretty simple and you can easily it give a try by running a Firefoxcontainer using the following Dockerfile as a starting point:

docker build -t firefox . it and run the container with:

If all goes well you should see Firefox running from within a Docker container.

Run Gui In Docker

Gui

Getting a NetBeans container up and running

Preparing a NetBeans base image was not that straightforward since we need toinstall some additional dependencies (namely the libxext-dev, libxrender-devand libxtst-dev packages) in order to get it to connect to the X11 socketproperly. I also had trouble using OpenJDK and had to switch to Oracle’s Javafor it to work.

After lots of trial and error, I was finally able to make it work and the resultis a base image available at the Docker Hubwith sources on GitHub.

Here’s a quick demo of it in action:

Future work

Over the next few months I’ll be working on a Play!app and will hopefully write a blog post on the workflow I used. Stay tunned for more :)

PS: This approach of sharing the X11 socket also be applied to vagrant-lxccontainers and I’ll document that on the project’s Wiki when Ihave a chance.