Zak
Zak

Reputation: 12653

`sudo docker build .` fails from Docker snap package

I run Ubuntu 16.04 and I have installed docker via a snap package. docker build is unable to access my Dockerfile, which sets in a sub-directory of ~.

The snap interface appears to be properly connected...

$ snap interfaces
Slot    Plug
...
:home   docker
...

However, when I call docker build (from the directory containing Dockerfile), I get the following error...

$ sudo docker build . -t serial-wiring.base
unable to prepare context: unable to evaluate symlinks in context path: lstat /home/<username>/Documents: permission denied

I am new to Docker, is there something I'm missing?

Here are the contents of the Dockerfile:

# Base Image
FROM ubuntu

# Add Required Packages [Layer 1]
RUN apt update && \
    apt install -y ca-certificates cmake g++ git make --no-install-recommends

# Download Sources [Layer 2]
RUN cd ~ && \
    git clone https://github.com/remote-wiring/serial-wiring.git && \
    cd serial-wiring/ && \
    mkdir build

# Verify Build and Install
CMD cd ~/serial-wiring/build/ && \
    cmake .. && \
    make

NOTE: I have confirmed docker build . -t serial-wiring.base works using this Dockerfile on Windows.

Upvotes: 1

Views: 1284

Answers (1)

Zak
Zak

Reputation: 12653

Due to confinement issues in the evolving snappy model, Docker is not full flavored by default (see the discussion on the Snapcraft forum).

To get some helpful instructions on how to work around (i.e. break) the confinement model until the proper fix is in place. You can simply check the Docker help application packaged in the snap.

$ docker.help
Docker snap: Docker Linux container runtime.

Due to the confinement issues on snappy, it requires some manual setup to make docker-snap works on your machine.
We'll take you through the steps needed to set up docker snap work for you on ubuntu core and ubuntu classic.

On Ubuntu classic, before installing the docker snap, 
please run the following command to add the login user into docker group.
    sudo addgroup --system docker
    sudo adduser $USER docker
    newgrp docker

On Ubuntu Core 16, after installing the docker snap from store,
Firstly, you need to connect the two interfaces as they're not auto-connected by default.
    sudo snap connect docker:account-control :account-control
    sudo snap connect docker:home :home

Secondly, reload the snap and allows the user to login to the new group "docker-snap".
    snap disable docker
    snap enable  docker
    newgrp docker-snap

Then have fun with docker in snappy.

The last command fails...

$ newgrp docker-snap
newgrp: group 'docker-snap' does not exist

However, I did not notice any negative impact based on the failure, and Docker now functions as I would expect.

Upvotes: 1

Related Questions