I got tired of this and used docker-machine with vmware driver. It's a bit tricky to set up to work as 'natural' as docker for mac (used wrapper for docker compose, some envvars-to-compose-file magic and shared folders), but IO is so much faster that it's worth it. It you folks have some spare time and a licence (or demo), try it.
Run the following to get access to a Python prompt running in a Docker container: docker run -i -t python:3.6 This is equivalent to: docker run -it python:3.6 Running the Jupyter Notebook After running the previous command, you should have entered the Python prompt. UPDATE: Looking back at @cgatian comments I tried to find out if Virtualization was enabled or not for my CPU. I am running a Intel Xeon CPU E5645 @ 2.40 GHz. I downloaded a program called SecurAble and found out that Hardware Virtualization is a No for my CPU and I don't see a Virtualization label when I run Task Manager as shown in the screenshot by cgatian.
Estimated reading time: 3 minutes
Docker Desktop for Mac is the Community version of Docker for Mac.You can download Docker Desktop for Mac from Docker Hub.
By downloading Docker Desktop, you agree to the terms of the Docker Software End User License Agreement and the Docker Data Processing Agreement.
Your Mac must meet the following requirements to successfully install Docker Desktop:
macOS must be version 10.14 or newer. That is, Mojave, Catalina, or Big Sur. We recommend upgrading to the latest version of macOS.
If you experience any issues after upgrading your macOS to version 10.15, you must install the latest version of Docker Desktop to be compatible with this version of macOS.
Docker supports Docker Desktop on the most recent versions of macOS. That is, the current release of macOS and the previous two releases. As new major versions of macOS are made generally available, Docker stops supporting the oldest version and supports the newest version of macOS (in addition to the previous two releases). Docker Desktop currently supports macOS Mojave, macOS Catalina, and macOS Big Sur.
At least 4 GB of RAM.
VirtualBox prior to version 4.3.30 must not be installed as it is not compatible with Docker Desktop.
What’s included in the installer
The Docker Desktop installation includes Docker Engine, Docker CLI client, Docker Compose, Notary, Kubernetes, and Credential Helper.
Install and run Docker Desktop on Mac
Docker.dmgto open the installer, then drag the Docker icon to the Applications folder.
Docker.appin the Applications folder to start Docker. (In the example below, the Applications folder is in “grid” view mode.)
The Docker menu in the top status bar indicates that Docker Desktop is running, and accessible from a terminal.
If you’ve just installed the app, Docker Desktop launches the onboarding tutorial. The tutorial includes a simple exercise to build an example Docker image, run it as a container, push and save the image to Docker Hub.
Click the Docker menu () to seePreferences and other options.
Select About Docker to verify that you have the latest version.
Congratulations! You are now successfully running Docker Desktop.
If you would like to rerun the tutorial, go to the Docker Desktop menu and select Learn.
Starting with Docker Desktop 3.0.0, updates to Docker Desktop will be available automatically as delta updates from the previous version.
When an update is available, Docker Desktop automatically downloads it to your machine and displays an icon to indicate the availability of a newer version. All you need to do now is to click Update and restart from the Docker menu. This installs the latest update and restarts Docker Desktop for the changes to take effect.
Uninstall Docker Desktop
To uninstall Docker Desktop from your Mac:
- From the Docker menu, select Troubleshoot and then select Uninstall.
- Click Uninstall to confirm your selection.
Uninstalling Docker Desktop destroys Docker containers, images, volumes, andother Docker related data local to the machine, and removes the files generatedby the application. Refer to the back up and restore datasection to learn how to preserve important data before uninstalling.
Where to go next
- Getting started provides an overview of Docker Desktop on Mac, basic Docker command examples, how to get help or give feedback, and links to other topics about Docker Desktop on Mac.
- Troubleshooting describes common problems, workarounds, howto run and submit diagnostics, and submit issues.
- FAQs provide answers to frequently asked questions.
- Release notes lists component updates, new features, and improvements associated with Docker Desktop releases.
- Get started with Docker provides a general Docker tutorial.
- Back up and restore data provides instructionson backing up and restoring data related to Docker.
Run a command in a new container
docker run command first
creates a writeable container layer over thespecified image, and then
starts it using the specified command. That is,
docker run is equivalent to the API
/containers/(id)/start. A stopped container can be restarted with all itsprevious changes intact using
docker start. See
docker ps -a to view a listof all containers.
docker run command can be used in combination with
docker commit tochange the command that a container runs. There is additional detailed information about
docker run in the Docker run reference.
For information on connecting a container to a network, see the “Docker network overview”.
For example uses of this command, refer to the examples section below.
|Add a custom host-to-IP mapping (host:ip)|
|Attach to STDIN, STDOUT or STDERR|
|Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)|
|Block IO weight (relative device weight)|
|Add Linux capabilities|
|Drop Linux capabilities|
|Optional parent cgroup for the container|
Cgroup namespace to use (host private)'host': Run the container in the Docker host's cgroup namespace'private': Run the container in its own private cgroup namespace': Use the cgroup namespace as configured by the default-cgroupns-mode option on the daemon (default)
|Write the container ID to the file|
|CPU count (Windows only)|
|CPU percent (Windows only)|
|Limit CPU CFS (Completely Fair Scheduler) period|
|Limit CPU CFS (Completely Fair Scheduler) quota|
Limit CPU real-time period in microseconds
Limit CPU real-time runtime in microseconds
|CPU shares (relative weight)|
Number of CPUs
|CPUs in which to allow execution (0-3, 0,1)|
|MEMs in which to allow execution (0-3, 0,1)|
|Run container in background and print container ID|
|Override the key sequence for detaching a container|
|Add a host device to the container|
|Add a rule to the cgroup allowed devices list|
|Limit read rate (bytes per second) from a device|
|Limit read rate (IO per second) from a device|
|Limit write rate (bytes per second) to a device|
|Limit write rate (IO per second) to a device|
|Skip image verification|
|Set custom DNS servers|
|Set DNS options|
|Set DNS options|
|Set custom DNS search domains|
|Container NIS domain name|
|Overwrite the default ENTRYPOINT of the image|
|Set environment variables|
|Read in a file of environment variables|
|Expose a port or a range of ports|
GPU devices to add to the container ('all' to pass all GPUs)
|Add additional groups to join|
|Command to run to check health|
|Time between running the check (ms s m h) (default 0s)|
|Consecutive failures needed to report unhealthy|
Start period for the container to initialize before starting health-retries countdown (ms s m h) (default 0s)
|Maximum time to allow one check to run (ms s m h) (default 0s)|
|Container host name|
Run an init inside the container that forwards signals and reaps processes
|Keep STDIN open even if not attached|
|Maximum IO bandwidth limit for the system drive (Windows only)|
|Maximum IOps limit for the system drive (Windows only)|
|IPv4 address (e.g., 172.30.100.104)|
|IPv6 address (e.g., 2001:db8::33)|
|IPC mode to use|
|Container isolation technology|
|Kernel memory limit|
|Set meta data on a container|
|Read in a line delimited file of labels|
|Add link to another container|
|Container IPv4/IPv6 link-local addresses|
|Logging driver for the container|
|Log driver options|
|Container MAC address (e.g., 92:d0:c6:0a:29:33)|
|Memory soft limit|
|Swap limit equal to memory plus swap: '-1' to enable unlimited swap|
|Tune container memory swappiness (0 to 100)|
|Attach a filesystem mount to the container|
|Assign a name to the container|
|Connect a container to a network|
|Add network-scoped alias for the container|
|Connect a container to a network|
|Add network-scoped alias for the container|
|Disable any container-specified HEALTHCHECK|
|Disable OOM Killer|
|Tune host's OOM preferences (-1000 to 1000)|
|PID namespace to use|
|Tune container pids limit (set -1 for unlimited)|
Set platform if server is multi-platform capable
|Give extended privileges to this container|
|Publish a container's port(s) to the host|
|Publish all exposed ports to random ports|
|Pull image before running ('always' 'missing' 'never')|
|Mount the container's root filesystem as read only|
|Restart policy to apply when a container exits|
|Automatically remove the container when it exits|
|Runtime to use for this container|
|Size of /dev/shm|
|Proxy received signals to the process|
|Signal to stop a container|
Timeout (in seconds) to stop a container
|Storage driver options for the container|
|Mount a tmpfs directory|
|Allocate a pseudo-TTY|
|Username or UID (format: <name uid>[:<group gid>])|
|User namespace to use|
|UTS namespace to use|
|Bind mount a volume|
|Optional volume driver for the container|
|Mount volumes from the specified container(s)|
|Working directory inside the container|
Assign name and allocate pseudo-TTY (--name, -it)
This example runs a container named
test using the
-it instructs Docker to allocate a pseudo-TTY connected tothe container’s stdin; creating an interactive
bash shell in the container.In the example, the
bash shell is quit by entering
exit 13. This exit code is passed on to the caller of
docker run, and is recorded in the
test container’s metadata.
Capture container ID (--cidfile)
This will create a container and print
test to the console. The
cidfileflag makes Docker attempt to create a new file and write the container ID to it.If the file exists already, Docker will return an error. Docker will close thisfile when
docker run exits.
Full container capabilities (--privileged)
This will not work, because by default, most potentially dangerous kernelcapabilities are dropped; including
cap_sys_admin (which is required to mountfilesystems). However, the
--privileged flag will allow it to run:
--privileged flag gives all capabilities to the container, and it alsolifts all the limitations enforced by the
device cgroup controller. In otherwords, the container can then do almost everything that the host can do. Thisflag exists to allow special use-cases, like running Docker within Docker.
Set working directory (-w)
-w lets the command being executed inside directory given, here
/path/to/dir/. If the path does not exist it is created inside the container.
Set storage driver options per container
This (size) will allow to set the container rootfs size to 120G at creation time.This option is only available for the
zfs graph drivers.For the
zfs graph drivers,user cannot pass a size less than the Default BaseFS Size.For the
overlay2 storage driver, the size option is only available if thebacking fs is
xfs and mounted with the
pquota mount option.Under these conditions, user can pass any size less than the backing fs size.
Mount tmpfs (--tmpfs)
--tmpfs flag mounts an empty tmpfs into the container with the
Mount volume (-v, --read-only)
-v flag mounts the current working directory into the container. The
-wlets the command being executed inside the current working directory, bychanging into the directory to the value returned by
pwd. So thiscombination executes the command using the container, but inside thecurrent working directory.
When the host directory of a bind-mounted volume doesn’t exist, Dockerwill automatically create this directory on the host for you. In theexample above, Docker will create the
/doesnt/existfolder before starting your container.
Volumes can be used in combination with
--read-only to control wherea container writes files. The
--read-only flag mounts the container’s rootfilesystem as read only prohibiting writes to locations other than thespecified volumes for the container.
By bind-mounting the docker unix socket and statically linked dockerbinary (refer to get the linux binary),you give the container the full access to create and manipulate the host’sDocker daemon.
On Windows, the paths must be specified using Windows-style semantics.
The following examples will fail when using Windows-based containers, as thedestination of a volume or bind mount inside the container must be one of:a non-existing or empty directory; or a drive other than C:. Further, the sourceof a bind mount must be a local directory, not a file.
For in-depth information about volumes, refer to manage data in containers
Add bind mounts or volumes using the --mount flag
--mount flag allows you to mount volumes, host-directories and
tmpfsmounts in a container.
--mount flag supports most options that are supported by the
-v or the
--volume flag, but uses a different syntax. For in-depth information on the
--mount flag, and a comparison between
--mount, refer tothe service create command reference.
Even though there is no plan to deprecate
--volume, usage of
--mount is recommended.
Publish or expose port (-p, --expose)
This binds port
8080 of the container to TCP port
127.0.0.1 of the hostmachine. You can also specify
sctp ports.The Docker User Guideexplains in detail how to manipulate ports in Docker.
Note that ports which are not bound to the host (i.e.,
-p 80:80 instead of
-p 127.0.0.1:80:80) will be accessible from the outside. This also applies ifyou configured UFW to block this specific port, as Docker manages hisown iptables rules. Read more
This exposes port
80 of the container without publishing the port to the hostsystem’s interfaces.
Set environment variables (-e, --env, --env-file)
--env-file flags to set simple (non-array)environment variables in the container you’re running, or overwrite variablesthat are defined in the Dockerfile of the image you’re running.
You can define the variable and its value when running the container:
You can also use variables that you’ve exported to your local environment:
When running the command, the Docker CLI client checks the value the variablehas in your local environment and passes it to the container.If no
= is provided and that variable is not exported in your localenvironment, the variable won’t be set in the container.
You can also load the environment variables from a file. This file should usethe syntax
<variable>=value (which sets the variable to the given value) or
<variable> (which takes the value from the local environment), and
# for comments.
Set metadata on container (-l, --label, --label-file)
A label is a
key=value pair that applies metadata to a container. To label a container with two labels:
my-label key doesn’t specify a value so the label defaults to an emptystring (
'). To add multiple labels, repeat the label flag (
key=value must be unique to avoid overwriting the label value. If youspecify labels with identical keys but different values, each subsequent valueoverwrites the previous. Docker uses the last
key=value you supply.
--label-file flag to load multiple labels from a file. Delimit eachlabel in the file with an EOL mark. The example below loads labels from alabels file in the current directory:
The label-file format is similar to the format for loading environmentvariables. (Unlike environment variables, labels are not visible to processesrunning inside a container.) The following example illustrates a label-fileformat:
You can load multiple label-files by supplying multiple
For additional information on working with labels, see Labels - custommetadata in Docker inthe Docker User Guide.
Connect a container to a network (--network)
When you start a container use the
--network flag to connect it to a network.This adds the
busybox container to the
You can also choose the IP addresses for the container with
--ip6flags when you start the container on a user-defined network.
If you want to add a running container to a network use the
docker network connect subcommand.
You can connect multiple containers to the same network. Once connected, thecontainers can communicate easily need only another container’s IP addressor name. For
overlay networks or custom plugins that support multi-hostconnectivity, containers connected to the same multi-host network but launchedfrom different Engines can also communicate in this way.
Service discovery is unavailable on the default bridge network. Containers cancommunicate via their IP addresses by default. To communicate by name, theymust be linked.
You can disconnect a container from a network using the
docker networkdisconnect command.
Mount volumes from container (--volumes-from)
--volumes-from flag mounts all the defined volumes from the referencedcontainers. Containers can be specified by repetitions of the
--volumes-fromargument. The container ID may be optionally suffixed with
:rw tomount the volumes in read-only or read-write mode, respectively. By default,the volumes are mounted in the same mode (read write or read only) asthe reference container.
Labeling systems like SELinux require that proper labels are placed on volumecontent mounted into a container. Without a label, the security system mightprevent the processes running inside the container from using the content. Bydefault, Docker does not change the labels set by the OS.
To change the label in the container context, you can add either of two suffixes
:Z to the volume mount. These suffixes tell Docker to relabel fileobjects on the shared volumes. The
z option tells Docker that two containersshare the volume content. As a result, Docker labels the content with a sharedcontent label. Shared volume labels allow all containers to read/write content.The
Z option tells Docker to label the content with a private unshared label.Only the current container can use a private volume.
Attach to STDIN/STDOUT/STDERR (-a)
-a flag tells
docker run to bind to the container’s
STDERR. This makes it possible to manipulate the output and input asneeded.
This pipes data into a container and prints the container’s ID by attachingonly to the container’s
This isn’t going to print anything unless there’s an error because we’veonly attached to the
STDERR of the container. The container’s logsstill store what’s been written to
This is how piping a file into a container could be done for a build.The container’s ID will be printed after the build is done and the buildlogs could be retrieved using
docker logs. This isuseful if you need to pipe a file or something else into a container andretrieve the container’s ID once the container has finished running.
Add host device to container (--device)
It is often necessary to directly expose devices to a container. The
--deviceoption enables that. For example, a specific block storage device or loopdevice or audio device can be added to an otherwise unprivileged container(without the
--privileged flag) and have the application directly access it.
By default, the container will be able to
mknod these devices.This can be overridden using a third
:rwm set of options to each
--deviceflag. If the container is running in privileged mode, then the permissions specifiedwill be ignored.
--device option cannot be safely used with ephemeral devices. Block devicesthat may be removed should not be added to untrusted containers with
For Windows, the format of the string passed to the
--device option is inthe form of
--device=<IdType>/<Id>. Beginning with Windows Server 2019and Windows 10 October 2018 Update, Windows only supports an IdType of
class and the Id as a device interface classGUID.Refer to the table defined in the Windows containerdocsfor a list of container-supported device interface class GUIDs.
If this option is specified for a process-isolated Windows container, alldevices that implement the requested device interface class GUID are madeavailable in the container. For example, the command below makes all COMports on the host visible in the container.
--device option is only supported on process-isolated Windows containers.This option fails if the container isolation is
hyperv or when running LinuxContainers on Windows (LCOW).
Access an NVIDIA GPU
--gpus flag allows you to access NVIDIA GPU resources. First you need toinstall nvidia-container-runtime.Visit Specify a container’s resourcesfor more information.
--gpus, specify which GPUs (or all) to use. If no value is provied, allavailable GPUs are used. The example below exposes all available GPUs.
device option to specify GPUs. The example below exposes a specificGPU.
The example below exposes the first and third GPUs.
Restart policies (--restart)
--restart to specify a container’s restart policy. A restartpolicy controls whether the Docker daemon restarts a container after exit.Docker supports the following restart policies:
|Do not automatically restart the container when it exits. This is the default.|
|Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts.|
|Restart the container unless it is explicitly stopped or Docker itself is stopped or restarted.|
|Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container.|
This will run the
redis container with a restart policy of alwaysso that if the container exits, Docker will restart it.
More detailed information on restart policies can be found in theRestart Policies (--restart)section of the Docker run reference page.
Add entries to container hosts file (--add-host)
You can add other hosts into a container’s
/etc/hosts file by using one ormore
--add-host flags. This example adds a static address for a host named
Sometimes you need to connect to the Docker host from within yourcontainer. To enable this, pass the Docker host’s IP address tothe container using the
--add-host flag. To find the host’s address,use the
ip addr show command.
Docker Run Mac Os
The flags you pass to
ip addr show depend on whether you areusing IPv4 or IPv6 networking in your containers. Use the followingflags for IPv4 address retrieval for a network device named
For IPv6 use the
-6 flag instead of the
-4 flag. For other networkdevices, replace
eth0 with the correct device name (for example
docker0for the bridge device).
Set ulimits in container (--ulimit)
ulimit settings in a container requires extra privileges notavailable in the default container, you can set these using the
--ulimit is specified with a soft and hard limit as such:
<type>=<soft limit>[:<hard limit>], for example:
If you do not provide a
hard limit, the
soft limit is usedfor both values. If no
ulimits are set, they are inherited fromthe default
ulimits set on the daemon. The
as option is disabled now.In other words, the following script is not supported:
The values are sent to the appropriate
syscall as they are set.Docker doesn’t perform any byte conversion. Take this into account when setting the values.
Be careful setting
nproc with the
ulimit flag as
nproc is designed by Linux to set themaximum number of processes available to a user, not to a container. For example, start fourcontainers with
Macos lion download. The 4th container fails and reports “ System error: resource temporarily unavailable” error.This fails because the caller set
nproc=3 resulting in the first three containers using upthe three processes quota set for the
Stop container with signal (--stop-signal)
--stop-signal flag sets the system call signal that will be sent to the container to exit.This signal can be a valid unsigned number that matches a position in the kernel’s syscall table, for instance 9,or a signal name in the format SIGNAME, for instance SIGKILL.
Optional security options (--security-opt)
On Windows, this flag can be used to specify the
credentialspec must be in the format
Stop container with timeout (--stop-timeout)
--stop-timeout flag sets the timeout (in seconds) that a pre-defined (see
--stop-signal) system callsignal that will be sent to the container to exit. After timeout elapses the container will be killed with SIGKILL.
Specify isolation technology for container (--isolation)
This option is useful in situations where you are running Docker containers onWindows. The
--isolation <value> option sets a container’s isolation technology.On Linux, the only supported is the
default option which usesLinux namespaces. These two commands are equivalent on Linux:
--isolation can take one of these values:
|Use the value specified by the Docker daemon’s |
|Shared-kernel namespace isolation (not supported on Windows client operating systems older than Windows 10 1809).|
|Hyper-V hypervisor partition-based isolation.|
The default isolation on Windows server operating systems is
process. The defaultisolation on Windows client operating systems is
hyperv. An attempt to start a container on a clientoperating system older than Windows 10 1809 with
--isolation process will fail.
On Windows server, assuming the default configuration, these commands are equivalentand result in
If you have set the
--exec-opt isolation=hyperv option on the Docker
daemon, orare running against a Windows client-based daemon, these commands are equivalent andresult in
Specify hard limits on memory available to containers (-m, --memory)
These parameters always set an upper limit on the memory available to the container. On Linux, thisis set on the cgroup and applications in a container can query it at
On Windows, this will affect containers differently depending on what type of isolation is used.
processisolation, Windows will report the full memory of the host system, not the limit to applications running inside the container
hypervisolation, Windows will create a utility VM that is big enough to hold the memory limit, plus the minimal OS needed to host the container. That size is reported as “Total Physical Memory.”
Configure namespaced kernel parameters (sysctls) at runtime
--sysctl sets namespaced kernel parameters (sysctls) in thecontainer. For example, to turn on IP forwarding in the containersnetwork namespace, run this command:
Not all sysctls are namespaced. Docker does not support changing sysctlsinside of a container that also modify the host system. As the kernelevolves we expect to see more sysctls become namespaced.
Currently supported sysctls
Docker Run Macos Image
- Sysctls beginning with
- If you use the
--ipc=hostoption these sysctls are not allowed.
- Sysctls beginning with
- If you use the
--network=hostoption using these sysctls are not allowed.
Docker Run Machine
Docker Run Macvlan Static Ip
|docker||The base command for the Docker CLI.|