Run Ubuntu On Docker

/ Comments off

Run a Docker Container in Ubuntu. In order to create and run a Docker container, first you need to run a command into a downloaded CentOS image, so a basic command would be to check the distribution version file inside the container using cat command, as shown. $ docker run centos cat /etc/issue 14. Docker run microsoft/dotnet-samples:dotnetapp-nanoserver-1809. The container will start, print the hello world message, and then exits. Running Linux Containers on Windows Server 2019. Out of the box, Docker on Windows only run Windows container. This is not a server platform upon which you will host websites, run server infrastructure, etc. For running production workloads on Ubuntu, we have some great solutions using Azure, Hyper-V, and Docker, and we have great tooling for developing containerized apps within Windows using Docker Tools for Visual Studio, Visual Studio Code and yo docker. Prior to WSL2, one could run the Docker client in WSL1, using it to drive Docker for Windows running atop Hyper-V on the local host, or to manage a remote Docker server. But one cannot run Docker Engine on WSL1 for many technical reasons. However, you can do the same in Docker on WSL2, but you can also run the Docker Engine itself atop WSL if.

Running Docker without Root Privileges: By default, you must run Docker as root user. You can also run Docker with sudo if it is configured on your Ubuntu 18.04 LTS machine. If you don’t want to use Docker as root user or with sudo, then you should add your login user to the docker group. Run Ubuntu In Docker On Windows 10; Run a Docker Container in Ubuntu. In order to create and run a Docker container, first you need to run a command into a downloaded CentOS image, so a basic command would be to check the distribution version file inside the container using cat command, as shown. $ docker run centos cat /etc/issue 14.

Estimated reading time: 15 minutes

Welcome to Docker Desktop! The Docker Desktop for Windows user manual provides information on how to configure and manage your Docker Desktop settings.

For information about Docker Desktop download, system requirements, and installation instructions, see Install Docker Desktop.


The Docker Desktop menu allows you to configure your Docker settings such as installation, updates, version channels, Docker Hub login,and more.

This section explains the configuration options accessible from the Settings dialog.

  1. Open the Docker Desktop menu by clicking the Docker icon in the Notifications area (or System tray):

  2. Select Settings to open the Settings dialog:


On the General tab of the Settings dialog, you can configure when to start and update Docker.

  • Start Docker when you log in - Automatically start Docker Desktop upon Windows system login.

  • Expose daemon on tcp://localhost:2375 without TLS - Click this option to enable legacy clients to connect to the Docker daemon. You must use this option with caution as exposing the daemon without TLS can result in remote code execution attacks.

  • Send usage statistics - By default, Docker Desktop sends diagnostics,crash reports, and usage data. This information helps Docker improve andtroubleshoot the application. Clear the check box to opt out. Docker may periodically prompt you for more information.


The Resources tab allows you to configure CPU, memory, disk, proxies, network, and other resources. Different settings are available for configuration depending on whether you are using Linux containers in WSL 2 mode, Linux containers in Hyper-V mode, or Windows containers.



The Advanced tab is only available in Hyper-V mode, because in WSL 2 mode and Windows container mode these resources are managed by Windows. In WSL 2 mode, you can configure limits on the memory, CPU, and swap size allocatedto the WSL 2 utility VM.

Use the Advanced tab to limit resources available to Docker.

CPUs: By default, Docker Desktop is set to use half the number of processorsavailable on the host machine. To increase processing power, set this to ahigher number; to decrease, lower the number.

Memory: By default, Docker Desktop is set to use 2 GB runtime memory,allocated from the total available memory on your machine. To increase the RAM, set this to a higher number. To decrease it, lower the number.

Swap: Configure swap file size as needed. The default is 1 GB.

Disk image size: Specify the size of the disk image.

Disk image location: Specify the location of the Linux volume where containers and images are stored.

You can also move the disk image to a different location. If you attempt to move a disk image to a location that already has one, you get a prompt asking if you want to use the existing image or replace it.

File sharing


The File sharing tab is only available in Hyper-V mode, because in WSL 2 mode and Windows container mode all files are automatically shared by Windows.

Use File sharing to allow local directories on Windows to be shared with Linux containers.This is especially useful forediting source code in an IDE on the host while running and testing the code in a container.Note that configuring file sharing is not necessary for Windows containers, only Linux containers. If a directory is not shared with a Linux container you may get file not found or cannot start service errors at runtime. See Volume mounting requires shared folders for Linux containers.

File share settings are:

  • Add a Directory: Click + and navigate to the directory you want to add.

  • Apply & Restart makes the directory available to containers using Docker’sbind mount (-v) feature.

Tips on shared folders, permissions, and volume mounts

  • Share only the directories that you need with the container. File sharing introduces overhead as any changes to the files on the host need to be notified to the Linux VM. Sharing too many files can lead to high CPU load and slow filesystem performance.

  • Shared folders are designed to allow application code to be edited on the host while being executed in containers. For non-code items such as cache directories or databases, the performance will be much better if they are stored in the Linux VM, using a data volume (named volume) or data container.

  • Docker Desktop sets permissions to read/write/execute for users, groups and others 0777 or a+rwx.This is not configurable. See Permissions errors on data directories for shared volumes.

  • Windows presents a case-insensitive view of the filesystem to applications while Linux is case-sensitive. On Linux it is possible to create 2 separate files: test and Test, while on Windows these filenames would actually refer to the same underlying file. This can lead to problems where an app works correctly on a developer Windows machine (where the file contents are shared) but fails when run in Linux in production (where the file contents are distinct). To avoid this, Docker Desktop insists that all shared files are accessed as their original case. Therefore if a file is created called test, it must be opened as test. Attempts to open Test will fail with “No such file or directory”. Similarly once a file called test is created, attempts to create a second file called Test will fail.

Shared folders on demand

You can share a folder “on demand” the first time a particular folder is used by a container.

If you run a Docker command from a shell with a volume mount (as shown in theexample below) or kick off a Compose file that includes volume mounts, you get apopup asking if you want to share the specified folder.

You can select to Share it, in which case it is added your Docker Desktop Shared Folders list and available tocontainers. Alternatively, you can opt not to share it by selecting Cancel.


Docker Desktop lets you configure HTTP/HTTPS Proxy Settings andautomatically propagates these to Docker. For example, if you set your proxysettings to, Docker uses this proxy when pulling containers.

Your proxy settings, however, will not be propagated into the containers you start.If you wish to set the proxy settings for your containers, you need to defineenvironment variables for them, just like you would do on Linux, for example:

For more information on setting environment variables for running containers,see Set environment variables.



The Network tab is not available in Windows container mode because networking is managed by Windows.

You can configure Docker Desktop networking to work on a virtual private network (VPN). Specify a network address translation (NAT) prefix and subnet mask to enable Internet connectivity.

DNS Server: You can configure the DNS server to use dynamic or static IP addressing.


Some users reported problems connecting to Docker Hub on Docker Desktop. This would manifest as an error when trying to rundocker commands that pull images from Docker Hub that are not alreadydownloaded, such as a first time run of docker run hello-world. If youencounter this, reset the DNS server to use the Google DNS fixed address: For more information, seeNetworking issues in Troubleshooting.

Run ubuntu on docker mac

Updating these settings requires a reconfiguration and reboot of the Linux VM.

WSL Integration

In WSL 2 mode, you can configure which WSL 2 distributions will have the Docker WSL integration.

By default, the integration will be enabled on your default WSL distribution. To change your default WSL distro, run wsl --set-default <distro name>. (For example, to set Ubuntu as your default WSL distro, run wsl --set-default ubuntu).

You can also select any additional distributions you would like to enable the WSL 2 integration on.

For more details on configuring Docker Desktop to use WSL 2, see Docker Desktop WSL 2 backend.

Docker Engine

The Docker Engine page allows you to configure the Docker daemon to determine how your containers run.

Type a JSON configuration file in the box to configure the daemon settings. For a full list of options, see the Docker Enginedockerd commandline reference.

Click Apply & Restart to save your settings and restart Docker Desktop.

Command Line

On the Command Line page, you can specify whether or not to enable experimental features.

You can toggle the experimental features on and off in Docker Desktop. If you toggle the experimental features off, Docker Desktop uses the current generally available release of Docker Engine.

Experimental features

Experimental features provide early access to future product functionality.These features are intended for testing and feedback only as they may changebetween releases without warning or can be removed entirely from a futurerelease. Experimental features must not be used in production environments.Docker does not offer support for experimental features.

For a list of current experimental features in the Docker CLI, see Docker CLI Experimental features.

Run docker version to verify whether you have enabled experimental features. Experimental modeis listed under Server data. If Experimental is true, then Docker isrunning in experimental mode, as shown here:



The Kubernetes tab is not available in Windows container mode.

Docker Desktop includes a standalone Kubernetes server that runs on your Windows machince, sothat you can test deploying your Docker workloads on Kubernetes. To enable Kubernetes support and install a standalone instance of Kubernetes running as a Docker container, select Enable Kubernetes.

For more information about using the Kubernetes integration with Docker Desktop, see Deploy on Kubernetes.


The Restart Docker Desktop and Reset to factory defaults options are now available on the Troubleshoot menu. For information, see Logs and Troubleshooting.


Visit our Logs and Troubleshooting guide for more details.

Log on to our Docker Desktop for Windows forum to get help from the community, review current user topics, or join a discussion.

Log on to Docker Desktop for Windows issues on GitHub to report bugs or problems and review community reported issues.

For information about providing feedback on the documentation or update it yourself, see Contribute to documentation.

Switch between Windows and Linux containers

From the Docker Desktop menu, you can toggle which daemon (Linux or Windows)the Docker CLI talks to. Select Switch to Windows containers to use Windowscontainers, or select Switch to Linux containers to use Linux containers(the default).

For more information on Windows containers, refer to the following documentation:

  • Microsoft documentation on Windows containers.

  • Build and Run Your First Windows Server Container (Blog Post)gives a quick tour of how to build and run native Docker Windows containers on Windows 10 and Windows Server 2016 evaluation releases.

  • Getting Started with Windows Containers (Lab)shows you how to use the MusicStoreapplication with Windows containers. The MusicStore is a standard .NET application and,forked here to use containers, is a good example of a multi-container application.

  • To understand how to connect to Windows containers from the local host, seeLimitations of Windows containers for localhost and published ports

Settings dialog changes with Windows containers

When you switch to Windows containers, the Settings dialog only shows those tabs that are active and apply to your Windows containers:

If you set proxies or daemon configuration in Windows containers mode, theseapply only on Windows containers. If you switch back to Linux containers,proxies and daemon configurations return to what you had set for Linuxcontainers. Your Windows container settings are retained and become availableagain when you switch back.


The Docker Desktop Dashboard enables you to interact with containers and applications and manage the lifecycle of your applications directly from your machine. The Dashboard UI shows all running, stopped, and started containers with their state. It provides an intuitive interface to perform common actions to inspect and manage containers and Docker Compose applications. For more information, see Docker Desktop Dashboard.

Docker Hub

Select Sign in /Create Docker ID from the Docker Desktop menu to access your Docker Hub account. Once logged in, you can access your Docker Hub repositories directly from the Docker Desktop menu.

For more information, refer to the following Docker Hub topics:

Two-factor authentication

Docker Desktop enables you to sign into Docker Hub using two-factor authentication. Two-factor authentication provides an extra layer of security when accessing your Docker Hub account.

You must enable two-factor authentication in Docker Hub before signing into your Docker Hub account through Docker Desktop. For instructions, see Enable two-factor authentication for Docker Hub.

After you have enabled two-factor authentication:

  1. Go to the Docker Desktop menu and then select Sign in / Create Docker ID.

  2. Enter your Docker ID and password and click Sign in.

  3. After you have successfully signed in, Docker Desktop prompts you to enter the authentication code. Enter the six-digit code from your phone and then click Verify.

After you have successfully authenticated, you can access your organizations and repositories directly from the Docker Desktop menu.

Adding TLS certificates

You can add trusted Certificate Authorities (CAs) to your Docker daemon to verify registry server certificates, and client certificates, to authenticate to registries.

How do I add custom CA certificates?

Docker Desktop supports all trusted Certificate Authorities (CAs) (root orintermediate). Docker recognizes certs stored under Trust RootCertification Authorities or Intermediate Certification Authorities.

Docker Desktop creates a certificate bundle of all user-trusted CAs based onthe Windows certificate store, and appends it to Moby trusted certificates. Therefore, if an enterprise SSL certificate is trusted by the user on the host, it is trusted by Docker Desktop.

To learn more about how to install a CA root certificate for the registry, seeVerify repository client with certificatesin the Docker Engine topics.

How do I add client certificates?

You can add your client certificatesin ~/.docker/certs.d/<MyRegistry>:<Port>/client.cert and~/.docker/certs.d/<MyRegistry>:<Port>/client.key. You do not need to push your certificates with git commands.

When the Docker Desktop application starts, it copies the~/.docker/certs.d folder on your Windows system to the /etc/docker/certs.ddirectory on Moby (the Docker Desktop virtual machine running on Hyper-V).

You need to restart Docker Desktop after making any changes to the keychainor to the ~/.docker/certs.d directory in order for the changes to take effect.

The registry cannot be listed as an insecure registry (seeDocker Daemon). Docker Desktop ignorescertificates listed under insecure registries, and does not send clientcertificates. Commands like docker run that attempt to pull from the registryproduce error messages on the command line, as well as on the registry.

Run Ubuntu On Docker

To learn more about how to set the client TLS certificate for verification, seeVerify repository client with certificatesin the Docker Engine topics.

Where to go next

  • Try out the walkthrough at Get Started.

  • Dig in deeper with Docker Labs example walkthroughs and source code.

  • Refer to the Docker CLI Reference Guide.

windows, edge, tutorial, run, docker, local, machine


Run ubuntu gui on docker

Run a command in a new container


Extended description

The 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/create then/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.

The 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.


Name, shorthandDefaultDescription
--add-hostAdd a custom host-to-IP mapping (host:ip)
--attach , -aAttach to STDIN, STDOUT or STDERR
--blkio-weightBlock IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--blkio-weight-deviceBlock IO weight (relative device weight)
--cap-addAdd Linux capabilities
--cap-dropDrop Linux capabilities
--cgroup-parentOptional parent cgroup for the container
--cgroupnsAPI 1.41+
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)
--cidfileWrite the container ID to the file
--cpu-countCPU count (Windows only)
--cpu-percentCPU percent (Windows only)
--cpu-periodLimit CPU CFS (Completely Fair Scheduler) period
--cpu-quotaLimit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-periodAPI 1.25+
Limit CPU real-time period in microseconds
--cpu-rt-runtimeAPI 1.25+
Limit CPU real-time runtime in microseconds
--cpu-shares , -cCPU shares (relative weight)
--cpusAPI 1.25+
Number of CPUs
--cpuset-cpusCPUs in which to allow execution (0-3, 0,1)
--cpuset-memsMEMs in which to allow execution (0-3, 0,1)
--detach , -dRun container in background and print container ID
--detach-keysOverride the key sequence for detaching a container
--deviceAdd a host device to the container
--device-cgroup-ruleAdd a rule to the cgroup allowed devices list
--device-read-bpsLimit read rate (bytes per second) from a device
--device-read-iopsLimit read rate (IO per second) from a device
--device-write-bpsLimit write rate (bytes per second) to a device
--device-write-iopsLimit write rate (IO per second) to a device
--disable-content-trusttrueSkip image verification
--dnsSet custom DNS servers
--dns-optSet DNS options
--dns-optionSet DNS options
--dns-searchSet custom DNS search domains
--domainnameContainer NIS domain name
--entrypointOverwrite the default ENTRYPOINT of the image
--env , -eSet environment variables
--env-fileRead in a file of environment variables
--exposeExpose a port or a range of ports
--gpusAPI 1.40+
GPU devices to add to the container ('all' to pass all GPUs)
--group-addAdd additional groups to join
--health-cmdCommand to run to check health
--health-intervalTime between running the check (ms s m h) (default 0s)
--health-retriesConsecutive failures needed to report unhealthy
--health-start-periodAPI 1.29+
Start period for the container to initialize before starting health-retries countdown (ms s m h) (default 0s)
--health-timeoutMaximum time to allow one check to run (ms s m h) (default 0s)
--helpPrint usage
--hostname , -hContainer host name
--initAPI 1.25+
Run an init inside the container that forwards signals and reaps processes
--interactive , -iKeep STDIN open even if not attached
--io-maxbandwidthMaximum IO bandwidth limit for the system drive (Windows only)
--io-maxiopsMaximum IOps limit for the system drive (Windows only)
--ipIPv4 address (e.g.,
--ip6IPv6 address (e.g., 2001:db8::33)
--ipcIPC mode to use
--isolationContainer isolation technology
--kernel-memoryKernel memory limit
--label , -lSet meta data on a container
--label-fileRead in a line delimited file of labels
--linkAdd link to another container
--link-local-ipContainer IPv4/IPv6 link-local addresses
--log-driverLogging driver for the container
--log-optLog driver options
--mac-addressContainer MAC address (e.g., 92:d0:c6:0a:29:33)
--memory , -mMemory limit
--memory-reservationMemory soft limit
--memory-swapSwap limit equal to memory plus swap: '-1' to enable unlimited swap
--memory-swappiness-1Tune container memory swappiness (0 to 100)
--mountAttach a filesystem mount to the container
--nameAssign a name to the container
--netConnect a container to a network
--net-aliasAdd network-scoped alias for the container
--networkConnect a container to a network
--network-aliasAdd network-scoped alias for the container
--no-healthcheckDisable any container-specified HEALTHCHECK
--oom-kill-disableDisable OOM Killer
--oom-score-adjTune host's OOM preferences (-1000 to 1000)
--pidPID namespace to use
--pids-limitTune container pids limit (set -1 for unlimited)
--platformAPI 1.32+
Set platform if server is multi-platform capable
--privilegedGive extended privileges to this container
--publish , -pPublish a container's port(s) to the host
--publish-all , -PPublish all exposed ports to random ports
--pullmissingPull image before running ('always' 'missing' 'never')
--read-onlyMount the container's root filesystem as read only
--restartnoRestart policy to apply when a container exits
--rmAutomatically remove the container when it exits
--runtimeRuntime to use for this container
--security-optSecurity Options
--shm-sizeSize of /dev/shm
--sig-proxytrueProxy received signals to the process
--stop-signalSIGTERMSignal to stop a container
--stop-timeoutAPI 1.25+
Timeout (in seconds) to stop a container
--storage-optStorage driver options for the container
--sysctlSysctl options
--tmpfsMount a tmpfs directory
--tty , -tAllocate a pseudo-TTY
--ulimitUlimit options
--user , -uUsername or UID (format: <name uid>[:<group gid>])
--usernsUser namespace to use
--utsUTS namespace to use
--volume , -vBind mount a volume
--volume-driverOptional volume driver for the container
--volumes-fromMount volumes from the specified container(s)
--workdir , -wWorking directory inside the container


Assign name and allocate pseudo-TTY (--name, -it)

This example runs a container named test using the debian:latestimage. 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 enteringexit 13. This exit code is passed on to the caller ofdocker 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:

The --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)

The -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 devicemapper, btrfs, overlay2,windowsfilter and zfs graph drivers.For the devicemapper, btrfs, windowsfilter and 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)

The --tmpfs flag mounts an empty tmpfs into the container with the rw,noexec, nosuid, size=65536k options.

Mount volume (-v, --read-only)

The -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.

Run Ubuntu On Docker Linux

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

The --mount flag allows you to mount volumes, host-directories and tmpfsmounts in a container.

The --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 --volume and --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 80 on of the hostmachine. You can also specify udp and 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 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)

Use the -e, --env, and --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:

The my-label key doesn’t specify a value so the label defaults to an emptystring ('). To add multiple labels, repeat the label flag (-l or --label).

The 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.

Use the --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 --label-file flags.

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 my-net network.

You can also choose the IP addresses for the container with --ip and --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)

The --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 :ro or :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 or :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.


The -a flag tells docker run to bind to the container’s STDIN, STDOUTor 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 STDIN.

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 STDERR and STDOUT.

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.

Run Ubuntu Docker On Centos

By default, the container will be able to read, write and 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.


The --device option cannot be safely used with ephemeral devices. Block devicesthat may be removed should not be added to untrusted containers with --device.

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 ofclass 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.


The --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

The --gpus­ flag allows you to access NVIDIA GPU resources. First you need toinstall nvidia-container-runtime.Visit Specify a container’s resourcesfor more information.

To use --gpus, specify which GPUs (or all) to use. If no value is provied, allavailable GPUs are used. The example below exposes all available GPUs.

Use the device option to specify GPUs. The example below exposes a specificGPU.

The example below exposes the first and third GPUs.

Restart policies (--restart)

Use Docker’s --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:

noDo not automatically restart the container when it exits. This is the default.
on-failure[:max-retries]Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts.
unless-stoppedRestart the container unless it is explicitly stopped or Docker itself is stopped or restarted.
alwaysAlways 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 nameddocker:

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.

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 eth0:

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)

Since setting ulimit settings in a container requires extra privileges notavailable in the default container, you can set these using the --ulimit flag.--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.

For nproc usage

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 daemon user:

The 4th container fails and reports “[8] 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 daemon user.

Stop container with signal (--stop-signal)

The --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 option.The credentialspec must be in the format file://spec.txt or registry://keyname.

Stop container with timeout (--stop-timeout)

The --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:

On Windows, --isolation can take one of these values:

defaultUse the value specified by the Docker daemon’s --exec-opt or system default (see below).
processShared-kernel namespace isolation (not supported on Windows client operating systems older than Windows 10 1809).
hypervHyper-V hypervisor partition-based isolation.

Run Ubuntu In Docker On Windows 7

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 process isolation:

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 hyperv isolation:

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 /sys/fs/cgroup/memory/memory.limit_in_bytes.

On Windows, this will affect containers differently depending on what type of isolation is used.

  • With process isolation, Windows will report the full memory of the host system, not the limit to applications running inside the container

  • With hyperv isolation, 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

The --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.

Start Ubuntu On Docker

Currently supported sysctls

IPC Namespace:

Can We Run Ubuntu Docker On Windows

  • kernel.msgmax, kernel.msgmnb, kernel.msgmni, kernel.sem,kernel.shmall, kernel.shmmax, kernel.shmmni, kernel.shm_rmid_forced.
  • Sysctls beginning with fs.mqueue.*
  • If you use the --ipc=host option these sysctls are not allowed.

Network Namespace:

Run Ubuntu On Docker Windows 10

  • Sysctls beginning with net.*
  • If you use the --network=host option using these sysctls are not allowed.

Run Ubuntu On Docker Windows

Parent command

Run Ubuntu In Docker On Windows 10

dockerThe base command for the Docker CLI.