Note

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

LXD/Docker in LXD

From Funtoo
< LXD
Revision as of 09:47, September 6, 2018 by Palica (talk | contribs)
Jump to navigation Jump to search

If you have followed our notes about LXD in LXD then there is not much you need to do to be able to run Docker inside your container.

   Note

The container has to be setup similarly as for LXD in LXD (security.nesting needs to be enabled) so let us know if you want this turned on for your container at bugs.funtoo.org

Let's start a simple Hello world docker container inside our LXD container.

Install and start docker

As simple as:

root # emerge -v app-emulation/docker
root # /etc/init.d/docker start

Starting your first docker microcontainer

root # docker run --detach --name app carinamarina/hello-world-app
root # docker run --detach --name web --link app:helloapp -p 80:5000 carinamarina/hello-world-web

Go to your containers ip address and if you were not running anything on port 80 you should get:

The linked container said... "Hello World!"

Building a Funtoo Docker Container

To build a docker container you will need a Dockerfile with the description how to build an image and internet connection and docker of course.

   
# This Dockerfile creates a funtoo stage3 container image. By default it
# creates a stage3 generic 64bit image. It utilizes a multi-stage build and requires
# docker-17.05.0 or later. It fetches a daily snapshot from the official
# sources and verifies its checksum as well as its gpg signature.

# As gpg keyservers sometimes are unreliable, we use multiple gpg server pools
# to fetch the signing key.

# we are going to use alpine as our bootstrap container
ARG BOOTSTRAP
FROM ${BOOTSTRAP:-alpine:3.7} as builder

WORKDIR /funtoo

# here are all the arguments about arch/subarch ... defined
ARG ARCH=x86-64bit
ARG SUBARCH=generic_64
ARG DIST="https://build.funtoo.org/funtoo-current"
ARG FILENAME="stage3-latest.tar.xz"
ARG BDFL_KEY="E986E8EE"
ARG BDFL_FP="E8EE"
ARG SIGNING_KEYS="11FD00FD 683A2F8A BEA87CD2 EEE54A43 62DD6D47 6B365A89"

RUN echo "Building Funtoo Container image for ${ARCH} ${SUFFIX} fetching from ${DIST}" \
 && sleep 3 \
 && apk --no-cache add gnupg tar wget xz \
 && STAGE3="${DIST}/${ARCH}/${SUBARCH}/${FILENAME}" \
 && wget -nv "${STAGE3}" "${STAGE3}.gpg" "${STAGE3}.hash.txt" \
 && gpg --list-keys \
 && echo "standard-resolver" >> ~/.gnupg/dirmngr.conf \
 && echo "honor-http-proxy" >> ~/.gnupg/dirmngr.conf \
 && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
 && gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys ${BDFL_KEY} ${SIGNING_KEYS} \
 && gpg --list-keys --fingerprint

And this is how we use it. Create a directory my_funtoo_img and put the Docker file in there. And then run this:

root # mkdir my_funtoo_img
root # cd my_funtoo_img
root # touch Dockerfile

Paste the contents inside Dockerfile and continue with:

root # docker build -t funtoo .
Sending build context to Docker daemon  4.096kB
Step 1/16 : ARG BOOTSTRAP           
Step 2/16 : FROM ${BOOTSTRAP:-alpine:3.7} as builder
 ---> 791c3e2ebfcb               
Step 3/16 : WORKDIR /funtoo            
 ---> Using cache                     
 ---> 55f68b42e50c              
Step 4/16 : ARG ARCH=x86-64bit     
 ---> Using cache               
 ---> 756b8f4d4229                 
Step 5/16 : ARG SUBARCH=generic_64   
 ---> Using cache               
 ---> be81f9929e20                  
Step 6/16 : ARG SUFFIX
 ---> Using cache
 ---> 5eaf818944d2
Step 7/16 : ARG DIST="https://build.funtoo.org/funtoo-current"
 ---> Using cache
 ---> ac85a6ef2c5d
Step 8/16 : ARG FILENAME="stage3-latest.tar.xz"
 ---> Using cache
 ---> 980145cd90ab
Step 9/16 : ARG BDFL_KEY="E986E8EE"
 ---> Using cache
 ---> e4a24bfc1232
Step 10/16 : ARG BDFL_FP="E8EE"
 ---> Using cache
 ---> 6e53c1d550bf
Step 11/16 : ARG SIGNING_KEYS="11FD00FD 683A2F8A BEA87CD2 EEE54A43 62DD6D47 6B365A89"
 ---> Using cache
 ---> 9576df27fa15
Step 12/16 : RUN echo "Building Funtoo Container image for ${ARCH} ${SUFFIX} fetching from ${DIST}"  && sleep 3  && apk --no-cache add gnupg tar wget xz  && STAGE3="${DIST}/${ARCH}/${SUBARCH}/${FILENAME}"  && ec
ho "STAGE3:" $STAGE3  && wget -nv "${STAGE3}" "${STAGE3}.gpg" "${STAGE3}.hash.txt"  && gpg --list-keys  && echo "standard-resolver" >> ~/.gnupg/dirmngr.conf  && echo "honor-http-proxy" >> ~/.gnupg/dirmngr.conf
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf  && gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys ${BDFL_KEY} ${SIGNING_KEYS}  && gpg --list-keys --fingerprint