Installing Docker and using containers

A container image is a lightweight, standalone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, and settings. In this way you don't need to install lots of libraries and software, you can use an existing image and start a container from it.

We will use a container with Ionic and Android SDK that will allow you to develop and test a mobile application. At the end, you will have an APK file that needs to be signed using Google Play Console and after that you can roll it out to millions of people.

In the same Ubuntu 16.04 in the Virtual Box used before, we will install and configure Docker:

  1. Install the GPG key in your system:
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key
add -
  1. Add a Docker repository to APT sources:
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu
$(lsb_release -cs) stable"
  1. Update the package database with the new added repository:
    sudo apt-get update  
  1. Install Docker Community Edition from the Docker repository instead of the Ubuntu repository:
    apt-cache policy docker-ce  

The output indicates that there are several versions available:

    docker-ce:
      Installed: (none)
      Candidate: 17.09.0~ce-0~ubuntu
      Version table:
         17.09.0~ce-0~ubuntu 500
            500 https://download.docker.com/linux/ubuntu xenial/stable
amd64 Packages
17.06.2~ce-0~ubuntu 500 500 https://download.docker.com/linux/ubuntu xenial/stable
amd64 Packages
17.06.1~ce-0~ubuntu 500 500 https://download.docker.com/linux/ubuntu xenial/stable
amd64 Packages
17.06.0~ce-0~ubuntu 500 500 https://download.docker.com/linux/ubuntu xenial/stable
amd64 Packages
17.03.2~ce-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable
amd64 Packages
17.03.1~ce-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable
amd64 Packages
17.03.0~ce-0~ubuntu-xenial 500 500 https://download.docker.com/linux/ubuntu xenial/stable
amd64 Packages
  1. Now install Docker:
    sudo apt-get install -y docker-ce  
  1. Verify your installed Docker version:
    sudo docker version
    Client:
     Version:      17.09.0-ce
     API version:  1.32
     Go version:   go1.8.3
     Git commit:   afdb6d4
     Built:        Tue Sep 26 22:42:18 2017
     OS/Arch:      linux/amd64
    Server:
     Version:      17.09.0-ce
     API version:  1.32 (minimum version 1.12)
     Go version:   go1.8.3
     Git commit:   afdb6d4
     Built:        Tue Sep 26 22:40:56 2017
     OS/Arch:      linux/amd64
     Experimental: false  
  1. Start Docker daemon on every boot:
    sudo systemctl status docker
    docker.service - Docker Application Container Engine
       Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
       Active: active (running) since Mon 2017-10-23 20:41:43 CEST; 46min ago
         Docs: https://docs.docker.com
     Main PID: 12117 (dockerd)
       CGroup: /system.slice/docker.service
               ├─12117 /usr/bin/dockerd -H fd://
               └─12141 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd
  
  1. In order to run docker commands without the sudo in front of them we need to add our user in the Docker group:
    sudo usermod -aG docker ${USER}  
  1. Now you need to log out and re-login to be able to run docker commands without sudo. Instead of that you can run this command:
    su - ${USER}  
  1. Verify that your user is in the Docker group with:
    id

The Docker group should be in the command output:

uid=1000(catalin) gid=1000(catalin) groups=1000(catalin),4(adm),20(dialout),
24(cdrom),26(tape),27(sudo),29(audio),30(dip),44(video),46(plugdev),
109(netdev),119(scanner),120(lpadmin),121(sambashare),998(docker)

Now Docker is installed and configured to run every time the virtual machine is started. To complete our setup for the mobile application we need to get the image that will be used to build and develop the mobile app and some starting code for the mobile application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.204.201