Code Monkey home page Code Monkey logo

docker's Introduction

docker

Docker Snap

This repository contains the source for the docker snap package. The package provides a distribution of Docker Community Edition (CE) for Ubuntu Core 16 (and other snap-compatible) systems. It is built from an upstream Docker CE release tag with some patches to fit the snap format and is available on armhf, arm64, amd64, i386, and ppc64el architectures. The rest of this page describes installation, usage, and development.

NOTE: Docker's official documentation (https://docs.docker.com) does not yet discuss the docker snap package.

Installation

To install the latest stable release of Docker CE using snap:

sudo snap install docker

If you are using Ubuntu Core 16,

  • Connect the docker:home plug as it's not auto-connected by default:
sudo snap connect docker:home

If you are using an alternative snap-compatible Linux distribution ("classic" in snap lingo), and would like to run docker as a normal user:

  • Create and join the docker group.
sudo addgroup --system docker
sudo adduser $USER docker
newgrp docker
  • You will also need to disable and re-enable the docker snap if you added the group while it was running.
sudo snap disable docker
sudo snap enable docker

Usage

Docker should function normally, with the following caveats:

  • All files that docker needs access to should live within your $HOME folder.

  • Additional certificates used by the Docker daemon to authenticate with registries need to be located in /var/snap/docker/common/etc/certs.d instead of /etc/docker/certs.d.

  • Specifying the option --security-opt="no-new-privileges=true" with the docker run command (or the equivalent in docker-compose) will result in a failure of the container to start. This is due to an an underlying external constraint on AppArmor (see https://bugs.launchpad.net/snappy/+bug/1908448 for details).

Examples

NVIDIA support

If the system is found to have an nvidia graphics card available, and the host has the required nvidia libraries installed, the nvidia container toolkit will be setup and configured to enable use of the local GPU from docker. This can be used to enable use of CUDA from a docker container, for instance.

To enable proper use of the GPU within docker, the nvidia runtime must be used. By default, the nvidia runtime will be configured to use CDI mode, and a the appropriate nvidia CDI config will be automatically created for the system. You just need to specify the nvidia runtime when running a container.

Ubuntu Core 22

The required nvidia libraries are available in the nvidia-core22 snap.

This requires connection of the graphics-core22 content interface provided by the nvidia-core22 snap, which should be automatically connected once installed.

Ubuntu Server / Desktop

The required nvidia libraries are available in the nvidia container toolkit packages.

Instruction on how to install them can be found (here)

Custom NVIDIA runtime config

If you want to make some adjustments to the automatically generated runtime config, you can use the nvidia-support.runtime.config-override snap config to completely replace it.

snap set docker nvidia-support.runtime.config-override="$(cat cutom-nvidia-config.toml)"

CDI device naming strategy

By default, the device-name-strategy for the CDI config will use index. Optionally, you can specify an alternative from the currently supported:

  • index
  • uuid
  • type-index
snap set docker nvidia-support.cdi.device-name-strategy=uuid

Disable NVIDIA support

Setting up the nvidia support should be automatic the hardware is present, but you may wish to specifically disable it so that setup is not even attempted. You can do so via the following snap config:

snap set docker nvidia-support.disabled=true

Usage examples

Generic example usage would look something like:

docker run --rm --runtime nvidia --gpus all {cuda-container-image-name}

or

docker run --rm --runtime nvidia --env NVIDIA_VISIBLE_DEVICES=all {cuda-container-image-name}

If your container image already has appropriate environment variables set, may be able to just specify the nvidia runtime with no additional args required.

Please refer to this guide for mode detail regarding environment variables that can be used.

NOTE: library path and discovery is automatically handled, but binary paths are not, so if you wish to test using something like the nvidia-smi binary passed into the container from the host, you could either specify the full path or set the PATH environment variable.

e.g.

docker run --rm --runtime=nvidia --gpus all --env PATH="${PATH}:/var/lib/snapd/hostfs/usr/bin" ubuntu nvidia-smi

Development

Developing the docker snap package is typically performed on a "classic" Ubuntu distribution. The instructions here are written for Ubuntu 16.04 "Xenial".

  • Install the snap tooling (requires snapd>2.21 and snapcraft>=2.26):
sudo apt-get install snapd snapcraft
sudo snap install core
  • Checkout this repository and build the docker snap package:
git clone https://github.com/docker/docker-snap
cd docker-snap
sudo snapcraft
  • Install the newly-created snap package:
sudo snap install --dangerous docker_[VER]_[ARCH].snap
  • Manually connect the relevant plugs and slots which are not auto-connected:
sudo snap connect docker:privileged :docker-support
sudo snap connect docker:support :docker-support
sudo snap connect docker:firewall-control :firewall-control
sudo snap connect docker:docker-cli docker:docker-daemon
sudo snap disable docker
sudo snap enable docker

You should end up with output similar to:

sudo snap interfaces docker
    Slot                  Plug
    :docker-support       docker:privileged,docker:support
    :firewall-control     docker
    :home                 docker
    :network              docker
    :network-bind         docker
    docker:docker-daemon  docker:docker-cli

Testing

We rely on spread (https://github.com/snapcore/spread) to run full-system test on Ubuntu Core 16. We also provide a utility script (run-spread-test.sh) to launch the spread test. It will

  1. Fetch primary snaps( kernel, core, gadget) and build custom Ubuntu Core image with them
  2. Boot the image in qemu emulator
  3. Deploy test suits in emulation environment
  4. Execute full-system testing

Firstly, install ubuntu-image tool since we need to create a custom Ubuntu Core image during test preparation.

sudo snap install --beta --classic ubuntu-image

Secondly, install qemu-kvm package since we use it as the backend to run the spread test.

sudo apt install qemu-kvm

Meanwhile, you need a classic-mode supported spread binary to launch kvm from its context. You can either build spread from this branch or download the spread snap package here.

sudo snap install --classic --dangerous spread_2017.05.24_amd64.snap

You may build the docker snap locally in advance and then execute the spread tests with the following commands:

snapcraft
./run-spread-tests.sh

When doing a local build, you can also specify --test-from-channel to fetch the snap from the specific channel of the store. The snap from candidate channel is used by default as test target if --channel option is not specified.

./run-spread-tests.sh --test-from-channel --channel=stable

In order to run an individual spread test, please run the following command:

spread spread/main/installation

This will run the test case under spread/main/installation folder. You can specify the SNAP_CHANNEL environment variable to install a snap from a specific channel for the testing as well.

SNAP_CHANNEL=candidate spread spread/main/update_policy

docker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

docker's Issues

Daemon options config hook

It would be desirable to let end-users configure extra options / override default options for the docker daemon. Ideally, this would be implemented with a config hook.

docker permanently restarts on rpi2

hiho.

my docker has many restarts after installing with snap install docker. dmesg output is full of:

[ 2386.934067] audit: type=1400 audit(1478425942.891:15996): apparmor="DENIED" operation="open" profile="snap.docker.dockerd" name="/var/lib/snapd/hostfs/sys/kernel/security/apparmor/" pid=24541 comm="apparmor_parser" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
[ 2386.940143] audit: type=1400 audit(1478425942.895:15997): apparmor="DENIED" operation="exec" profile="snap.docker.dockerd" name="/bin/kmod" pid=24542 comm="docker" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
[ 2387.147858] audit: type=1400 audit(1478425943.103:15998): apparmor="DENIED" operation="exec" profile="snap.docker.dockerd" name="/bin/kmod" pid=24543 comm="docker" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
[ 2387.153727] audit: type=1400 audit(1478425943.111:15999): apparmor="DENIED" operation="exec" profile="snap.docker.dockerd" name="/bin/kmod" pid=24544 comm="docker" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
[ 2387.158996] audit: type=1400 audit(1478425943.115:16000): apparmor="DENIED" operation="exec" profile="snap.docker.dockerd" name="/bin/kmod" pid=24545 comm="docker" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
[ 2387.181619] audit: type=1400 audit(1478425943.135:16001): apparmor="DENIED" operation="exec" profile="snap.docker.dockerd" name="/sbin/xtables-multi" pid=24546 comm="docker" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
[ 2387.186725] audit: type=1400 audit(1478425943.143:16002): apparmor="DENIED" operation="exec" profile="snap.docker.dockerd" name="/sbin/xtables-multi" pid=24547 comm="docker" requested_mask="x" denied_mask="x" fsuid=0 ouid=0
[ 2387.192455] audit: type=1400 audit(1478425943.147:16003): apparmor="DENIED" operation="exec" profile="snap.docker.dockerd" name="/sbin/xtables-multi" pid=24548 comm="docker" requested_mask="x" denied_mask="x" fsuid=0 ouid=0

how can this be debuged?

Docker version bump

Hello there,

What are your plans for Docker 1.12? I'm anxious to use swarm mode on ubuntu core 16.

Thanks,

cannot open mount namespace file for namespace group docker. errmsg: Permission denied

I am trying to use docker via another snap (cumulocity). This is essentially a java management app that can make a system call.

After a fresh install or rebooting my hardware I can issue /snap/bin/docker ps -a successfully via this management app ONCE. But when I re-issue the very same command the second time, I get this error:

cannot open mount namespace file for namespace group docker. errmsg: Permission denied

Then I can repeat the docker command any times via the mgm app, I get the error consistently.
If I use the sudo docker ps -a command from the console, it always works.

Here is my config:

triesz@localhost:~$ snap list 
Name        Version     Rev  Developer  Notes
core        16.04.1     378  canonical  -
cumulocity  7.37.0      x2              devmode
docker      1.11.2-9    49   canonical  -
pc          16.04-0.8   9    canonical  -
pc-kernel   4.4.0-45-4  37   canonical  -
triesz@localhost:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
triesz@localhost:~$ snap interfaces
Slot                    Plug
:bluetooth-control      -
:camera                 -
:dcdbas-control         -
:docker-support         docker:privileged,docker:support
:firewall-control       cumulocity,docker
:fuse-support           -
:hardware-observe       -
:home                   cumulocity,docker
:kernel-module-control  -
:locale-control         -
:log-observe            -
:lxd-support            -
:mount-observe          -
:network                cumulocity,docker
:network-bind           cumulocity,docker
:network-control        -
:network-observe        -
:network-setup-observe  -
:opengl                 -
:ppp                    -
:process-control        cumulocity
:removable-media        -
:shutdown               -
:snapd-control          -
:system-observe         -
:system-trace           -
:time-control           -
:timeserver-control     -
:timezone-control       -
:tpm                    -
docker:docker-daemon    cumulocity:docker,docker:docker-cli
triesz@localhost:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
triesz@localhost:~$ 

syslog extract after the first, successful command execution (via the cumulocity mgm app)

Nov  1 18:04:17 localhost kernel: [   93.334736] audit_printk_skb: 72 callbacks suppressed
Nov  1 18:04:17 localhost kernel: [   93.334740] audit: type=1400 audit(1478023457.825:46): apparmor="ALLOWED" operation="exec" profile="snap.cumulocity.cumulocity" name="/usr/bin/snap" pid=1413 comm="java" requested_mask="x" denied_mask="x" fsuid=0 ouid=0 target="snap.cumulocity.cumulocity//null-/usr/bin/snap"
Nov  1 18:04:17 localhost kernel: [   93.335707] audit: type=1400 audit(1478023457.829:47): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/etc/ld.so.cache" pid=1413 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:04:17 localhost kernel: [   93.335777] audit: type=1400 audit(1478023457.829:48): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/lib/x86_64-linux-gnu/libpthread-2.23.so" pid=1413 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:04:17 localhost kernel: [   93.335864] audit: type=1400 audit(1478023457.829:49): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/lib/x86_64-linux-gnu/libc-2.23.so" pid=1413 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:04:17 localhost kernel: [   93.336020] audit: type=1400 audit(1478023457.829:50): apparmor="ALLOWED" operation="file_mprotect" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/bin/snap" pid=1413 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:04:17 localhost kernel: [   93.336076] audit: type=1400 audit(1478023457.829:51): apparmor="ALLOWED" operation="file_mprotect" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/lib/x86_64-linux-gnu/ld-2.23.so" pid=1413 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:04:17 localhost kernel: [   93.337182] audit: type=1400 audit(1478023457.829:52): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/lib/locale/C.UTF-8/LC_IDENTIFICATION" pid=1413 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:04:17 localhost kernel: [   93.337262] audit: type=1400 audit(1478023457.829:53): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache" pid=1413 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:04:17 localhost kernel: [   93.337329] audit: type=1400 audit(1478023457.829:54): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/lib/locale/C.UTF-8/LC_MEASUREMENT" pid=1413 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:04:17 localhost kernel: [   93.337373] audit: type=1400 audit(1478023457.829:55): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/lib/locale/C.UTF-8/LC_TELEPHONE" pid=1413 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:04:17 localhost snap[1201]: time="2016-11-01T18:04:17.866499276Z" level=debug msg="Calling GET /v1.23/containers/json?all=1"

syslog extract when using the command the second time:

Nov  1 18:06:27 localhost kernel: [  222.848659] audit_printk_skb: 291 callbacks suppressed
Nov  1 18:06:27 localhost kernel: [  222.848666] audit: type=1400 audit(1478023587.341:153): apparmor="ALLOWED" operation="exec" profile="snap.cumulocity.cumulocity" name="/usr/bin/snap" pid=1426 comm="java" requested_mask="x" denied_mask="x" fsuid=0 ouid=0 target="snap.cumulocity.cumulocity//null-/usr/bin/snap"
Nov  1 18:06:27 localhost kernel: [  222.849682] audit: type=1400 audit(1478023587.341:154): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/etc/ld.so.cache" pid=1426 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:06:27 localhost kernel: [  222.849863] audit: type=1400 audit(1478023587.341:155): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/lib/x86_64-linux-gnu/libpthread-2.23.so" pid=1426 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:06:27 localhost kernel: [  222.850125] audit: type=1400 audit(1478023587.341:156): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/lib/x86_64-linux-gnu/libc-2.23.so" pid=1426 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:06:27 localhost kernel: [  222.850553] audit: type=1400 audit(1478023587.341:157): apparmor="ALLOWED" operation="file_mprotect" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/bin/snap" pid=1426 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:06:27 localhost kernel: [  222.850689] audit: type=1400 audit(1478023587.341:158): apparmor="ALLOWED" operation="file_mprotect" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/lib/x86_64-linux-gnu/ld-2.23.so" pid=1426 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:06:27 localhost kernel: [  222.855415] audit: type=1400 audit(1478023587.349:159): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/lib/locale/C.UTF-8/LC_IDENTIFICATION" pid=1426 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:06:27 localhost kernel: [  222.855627] audit: type=1400 audit(1478023587.349:160): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache" pid=1426 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:06:27 localhost kernel: [  222.855769] audit: type=1400 audit(1478023587.349:161): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/lib/locale/C.UTF-8/LC_MEASUREMENT" pid=1426 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Nov  1 18:06:27 localhost kernel: [  222.855925] audit: type=1400 audit(1478023587.349:162): apparmor="ALLOWED" operation="open" profile="snap.cumulocity.cumulocity//null-/usr/bin/snap" name="/usr/lib/locale/C.UTF-8/LC_TELEPHONE" pid=1426 comm="docker" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

I built the cumulocity snapp this way:

name: cumulocity
version: "7.37.0"
summary: cumulocity java agent on openJDK
description: cumulocity java agent on openJDK
confinement: devmode

apps:
  cumulocity:
    command: launch_cumulo.sh
    daemon: simple
    plugs: [network, home, docker, process-control, network-bind, firewall-control]

parts:
  cumulocity:
    source: .
    plugin: dump
  java:
    source: .
    plugin: jdk

is this the correct way to expose docker to another snap?

"oci runtime error" when run hello-world container

The command I used to test is
$docker run --rm hello-world

It can download the image but it failed when it tried to start the container.

Hardware and software: all-snap image on x86-64 computer.

$ snap list
Name Version Rev Developer Notes
core 16.04.1 394 canonical -
docker 1.11.2-9 53 canonical -
pc 16.04-0.8 9 canonical -
pc-kernel 4.4.0-45-4 37 canonical -

Error messages are like below:
Nov 9 16:47:36 localhost kernel: [82650.637069] audit: type=1400 audit(1478710056.851:11530): apparmor="DENIED" operation="mkdir" profile="snap.docker.dockerd" name="/var/lib/snapd/hostfs/sys/fs/cgroup/cpuset/docker/" pid=10731 comm="docker-runc" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Nov 9 16:47:36 localhost snap[9923]: time="2016-11-09T16:47:36Z" level=error msg="containerd: start container" error="oci runtime error: mkdir /var/lib/snapd/hostfs/sys/fs/cgroup/cpuset/docker: permission denied" id=f7433fe81e60051eafb26c888732135414a747ef1d7bcf58fe93a4f7dde45c29

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.