Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

May 4, 2018

Docker with openSUSE Leap 15

Docker with openSUSE Leap 15

OS: openSUSE Leap 15.0 Beta
Docker version:  17.09.1-ce

Docker is a software technology providing containers, promoted by the company Docker, Inc. Docker provides an additional layer of abstraction and automation of operating-system-level virtualization on Windows and Linux.
Docker implements a high-level API to provide lightweight containers that run processes in isolation.
Because Docker containers are so lightweight, a single server or virtual machine can run several containers simultaneously.

Let’s do some hands on with docker and openSUSE Leap 15

== Install Docker  ==

Use GUI method
use yast2  sw_single install docker

# yast2  sw_single

Search  docker
Select docker to install



Use command line to install docker

use zypper to install, if you don’t want interactive use #zypper  -n install docker
# zypper  install  docker

Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 13 NEW packages are going to be installed:
 containerd criu docker docker-bash-completion docker-libnetwork docker-runc git-core git-gui gitk libnet9
 libsha1detectcoll1 python2-ipaddr python2-protobuf

The following recommended package was automatically selected:
 criu

13 new packages to install.
Overall download size: 23.2 MiB. Already cached: 0 B. After the operation, additional 117.1 MiB will be used.
Continue? [y/n/...? shows all options] (y):  Y


Check docker version when you install it
# docker  --version
Docker version 17.09.1-ce, build f4ffd2511ce9


== Start docker service and setup boot enable  ==

GUI method
Use yast2  services-manager
# yast2  services-manager

click docker
click Start/Stop start docker service
click Enable/Disable Setup boot enable docker service
Click OK




Command line method

use systemctl command

Check docker service status
# systemctl  status  docker

* docker.service - Docker Application Container Engine
  Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
  Active: inactive (dead)
    Docs: http://docs.docker.com



Start  docker service
# systemctl  start   docker

# systemctl  status docker

* docker.service - Docker Application Container Engine
  Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
  Active: active (running) since Fri 2018-04-27 21:24:09 CST; 3s ago
    Docs: http://docs.docker.com
Main PID: 13632 (dockerd)
   Tasks: 9



Setup boot enable docker service

Checking boot status
# systemctl  is-enabled docker
disabled

Setup boot enable docker
# systemctl  enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service -> /usr/lib/systemd/system/docker.service.


# systemctl  is-enabled docker
enabled


== If you want normal user could use docker command  ==

The docker package creates a new group named docker. Users, other than root user, need to be part of this group in order to interact with the Docker daemon. You can add users with:
#usermod   -a -G docker   

Like

#usermod   -a -G docker   max



Practice:  docker basic command

Check Docker version

# docker  --version
Docker version 17.09.1-ce, build f4ffd2511ce9

Pull your first  docker image

# docker  pull   busybox
Using default tag: latest
latest: Pulling from library/busybox
f70adabe43c0: Pull complete
Digest: sha256:58ac43b2cc92c687a32c8be6278e50a063579655fe3090125dcb2af0ff9e1a64
Status: Downloaded newer image for busybox:latest


Check your docker images
# docker  images
REPOSITORY          TAG IMAGE ID            CREATED SIZE
busybox             latest 8ac48589692a        3 weeks ago 1.15MB


Search docker images on the web

For example, search opensuse



Search docker images with command

# docker  search  opensuse
NAME                                  DESCRIPTION          STARS OFFICIAL AUTOMATED
opensuse                              This project contains the stable releases ...   230 [OK]
opensuse/portus                       Production ready Docker image of Portus.        65 [OK]


Get your openSUSE docker images  :)
Default is latest if you not order tag

# docker  pull   opensuse
Using default tag: latest
latest: Pulling from library/opensuse
47aa660240a8: Pull complete
Digest: sha256:569e6ee7a622838b9fa1111c3bfa99a50fdb34b7503f945b7d18ce66bb94a369
Status: Downloaded newer image for opensuse:latest

Check your docker images again

# docker  images
REPOSITORY          TAG IMAGE ID            CREATED SIZE
opensuse            latest 35057ab4ef08        6 days ago 110MB
busybox             latest 8ac48589692a        3 weeks ago 1.15MB

Get docker image with tag

# docker  pull  opensuse:42.3
42.3: Pulling from library/opensuse
Digest: sha256:569e6ee7a622838b9fa1111c3bfa99a50fdb34b7503f945b7d18ce66bb94a369
Status: Downloaded newer image for opensuse:42.3


Check your docker images again, you will see opensuse:latest and opensuse:42.3 has the same  IMAGE ID because they are the same.

# docker  images
REPOSITORY          TAG IMAGE ID            CREATED SIZE
opensuse            42.3 35057ab4ef08        6 days ago          110MB
opensuse            latest 35057ab4ef08        6 days ago          110MB
busybox             latest 8ac48589692a        3 weeks ago 1.15MB

Of course, you could pull other images from docker hub, for example

# docker  pull  sakana/sshd
Using default tag: latest
latest: Pulling from sakana/sshd
Digest: sha256:8f140e190db2d683b36cbac1d57410cdfb67029c4580b7b3aad3730005936544
Status: Downloaded newer image for sakana/sshd:latest


Practice:  Run docker container

Know your docker container status before you go
You will not see anything when you use #docker ps command

# docker  ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES


# docker   ps   -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Run your first docker container with openSUSE

# docker   run   --rm   -i  -t   opensuse   /bin/bash
  • run execute docker
  • --rm Automatically remove the container when it exits
  • -i Keep STDIN open even if not attached
  • -t Allocate a pseudo-TTY

In the container
You could try to echo $HOSTNAME to check you are in docker contaienr now.

00172605a6e5:/ # echo $HOSTNAME
00172605a6e5

Leave the container

00172605a6e5:/ # exit
exit
Check docker container status with #docker ps

# docker  ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES


# docker   ps   -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES


Run docker container again without  --rm

# docker   run   -i  -t   opensuse   /bin/bash

Leave the docker container

62d16d591ad0:/ # exit
exit

Check docker container status with #docker ps
You will find -- if you not use --rm option, docker container will not remove from your host.

# docker  ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES


# docker   ps   -a
CONTAINER ID        IMAGE COMMAND             CREATED STATUS             PORTS NAMES
62d16d591ad0        opensuse "/bin/bash"         About a minute ago Exited (0) About a minute ago                       quizzical_almeida

Mar 31, 2016

docker unstable package install with openSUSE Leap 42.1 ( + ansible )

20160331

I need install docker unstable version with testbed, so I write the note and ansible playbook with openSUSE Leap 42.1

OS: openSUSE Leap 42.1
Package: docker 1.10.x

docker in openSUSE Leap 42.1 is 1.9.x now.

How to query your docker version?

# zypper   search   -s   --match-exact   docker
Loading repository data...
Reading installed packages...

S | Name   | Type       | Version    | Arch   | Repository               
--+--------+------------+------------+--------+--------------------------
 | docker | package    | 1.9.1-13.1 | x86_64 | openSUSE-Leap-42.1-Update
 | docker | package    | 1.9.1-10.1 | x86_64 | openSUSE-Leap-42.1-Update
 | docker | package    | 1.9.1-7.1  | x86_64 | openSUSE-Leap-42.1-Update
 | docker | package    | 1.9.0-4.1  | x86_64 | openSUSE-Leap-42.1-Update
 | docker | package    | 1.8.2-2.5  | x86_64 | openSUSE-Leap-42.1-Oss   

  • -s - detail, but not much than -v "verbose"
  • --match-exact - match the package name
    • like --match-words ^docker$

I want to install docker with batch mode or non-interactive

First idea
*Use OneClickInstallCLI with .ymp file
Here is the link

But OneClickInstallCLI can't use non-interactive mode -- Give up


Use blow method now
in software.opensuse.org search docker

click Virtualization:container
2016-03-31 10-29-59 的螢幕擷圖.png

In project web page
Click Repositories
You will see The repositories are inherited from the project Virtualization:containers.
Click Virtualization:containers -- > Click Repositories

You could see each version repositories download

2016-03-31 10-41-29 的螢幕擷圖.png

I use Leap 42.1 so click openSUSE_Leap 42.1 link, like

You could see the .repo file in web page

2016-03-31 10-44-31 的螢幕擷圖.png

link is

Use zypper to add repo, key and setup auto refresh

  • --gpg-auto-import-keys  - auto add repo key
  • -f - auto refresh


Check your repos by zypper command


# zypper   repos
#  | Alias                     | Name                                           | Enabled | GPG Check | Refresh
---+---------------------------+------------------------------------------------+---------+-----------+--------
1 | Virtualization_containers | Virtualization:containers (openSUSE_Leap_42.1) | Yes     | ( p) Yes  | Yes    
2 | openSUSE-42.1-0           | openSUSE-42.1-0                                | No      | ----      | No     


# zypper  -n  install  docker
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 7 NEW packages are going to be installed:
 bridge-utils docker docker-image-migrator git-core git-gui gitk perl-Error

The following recommended package was automatically selected:
 docker-image-migrator

7 new packages to install.
Overall download size: 12.9 MiB. Already cached: 0 B. After the operation, additional 59.4 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package docker-image-migrator-1.0.2-7.1.x86_64           


Set up docker start and boot enable


# systemctl   status  docker
docker.service - Docker Application Container Engine
  Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled)
  Active: inactive (dead)
    Docs: http://docs.docker.com

start docker service
# systemctl  start   docker


# systemctl  status docker
docker.service - Docker Application Container Engine
  Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled)
  Active: active (running) since Thu 2016-03-31 11:00:58 CST; 2s ago
    Docs: http://docs.docker.com
Main PID: 32272 (docker)
  CGroup: /system.slice/docker.service
          └─32272 /usr/bin/docker daemon -H fd://

Set up boot enable


# systemctl  is-enabled  docker
disabled

enable start at boot
# systemctl  enable  docker


# systemctl  is-enabled   docker
enabled


-------------------------------------------------

I write ansible playbook .yml for insatll with ansible
You could get it at github 

Here is my ansible playbook yml file
# cat   docker_unstable_openSUSELeap42.1_install.yml
---
#########################################################  
# Install docker package and setup boot with unstable repo in openSUSE Leap 42.1
- name: use when conditionals and setup module (facts)
 hosts: all
 tasks:
# 使用 setup moudule 列出 OS 種類
   - name: use setup module to list os distribution
# setup moudle 可以使用 filter 過濾相關內容
     setup: filter=ansible_distribution


#########################################################  

- name: Install docker and run service
# use [dockerUnstable] group to install
 hosts: dockerUnstable
 sudo: True
 tasks:
# Add Virtualization:container project repo
   - name: Add Virutalization:containers repo
     shell: zypper  --gpg-auto-import-keys   addrepo   -f http://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Leap_42.1/Virtualization:containers.repo

   - name: Install docker with openSUSE Leap
     zypper: name={{ item }}
     with_items:
       - docker
       - curl
     when: ansible_distribution == "openSUSE Leap"


#-------------------------------------------------------  

   - name: Set docker enable and run
     service: name=docker state=started enabled=yes