Recent Tutorials and Articles
    Installing Docker on Ubuntu/CentOS using Snap Packages
    Published on: 2018-10-19 02:10:08
    Posted By: Amit Kumar

    This tutorial describes how to install, manage and uninstall docker on Ubuntu/CentOS using Snap packages of Linux.

    Introduction to Snap Packages


    Snap packages are universal Linux packages that make it easy to deploy applications/softwares on any Linux distribution. This requires the need of handling different package managers for different Linux distributions.

    In this article, we will see how we can manage Docker installation using Snap.

     

    Installing Docker using Snap


    First step is to check versions available for Docker in Snap packages using below command - 

    snap info docker

    Here is the output of above command for me - 

    name:      docker                                                                                                                                                                                            
    summary:   The docker app deployment mechanism                                                                                                                                                               
    publisher: Docker, Inc (docker-inc)                                                                                                                                                                          
    contact:   [email protected]                                                                                                                                                                     
    license:   Apache-2.0                                                                                                                                                                                        
    description: |                                                                                                                                                                                               
      Docker for snappy.                                                                                                                                                                                         
                                                                                                                                                                                                                 
      This snap allows you to use the full capabilities of docker on snappy.                                                                                                                                     
                                                                                                                                                                                                                 
      In order to use 'docker build', 'docker save' and 'docker load', you need to place your dockerfile                                                                                                         
      within $HOME. All files that you want docker to access to must be within this path.                                                                                                                        
                                                                                                                                                                                                                 
      You may also use the 'docker-privilege' command to allow you to use 'docker run --privileged'.                                                                                                             
      Because docker is unencumbered on snappy, it is recommended that you follow the Docker project's                                                                                                           
      recommendations for using docker securely.                                                                                                                                                                 
    snap-id: sLCsFAO8PKM5Z0fAKNszUOX0YASjQfeZ                                                                                                                                                                    
    channels:                                                                                                                                                                                                    
      stable:          18.06.1-ce   (321) 102MB -                                                                                                                                                                
      candidate:       18.06.1-ce   (321) 102MB -                                                                                                                                                                
      beta:            18.06.1-ce   (321) 102MB -                                                                                                                                                                
      edge:            18.06.1-ce   (321) 102MB -                                                                                                                                                                
      17.09/stable:    –                                                                                                                                                                                         
      17.09/candidate: 17.09.1-ce   (232) 44MB  -                                                                                                                                                                
      17.09/beta:      17.09.1-ce   (232) 44MB  -                                                                                                                                                                
      17.09/edge:      17.09.1-ce   (232) 44MB  -                                                                                                                                                                
      17.06/stable:    17.06.2-ce   (179) 43MB  -                                                                                                                                                                
      17.06/candidate: 17.06.2-ce   (179) 43MB  -                                                                                                                                                                
      17.06/beta:      ↑                                                                                                                                                                                         
      17.06/edge:      17.06.2-ce-1 (237) 44MB  -                                                                                                                                                                
      17.03/stable:    17.03.2-ce-1 (159) 42MB  -                                                                                                                                                                
      17.03/candidate: 17.03.2-ce-1 (159) 42MB  -                                                                                                                                                                
      17.03/beta:      ↑                                                                                                                                                                                         
      17.03/edge:      17.03.2-ce-1 (159) 42MB  -     

    Next is to install docker using one of the channels (deployment packages) available as follows - 

    # Install from stable channel
    sudo snap install docker
    
    # Install from a specific channel for deploying older versions
    sudo snap install --channel=<channel-name> docker
    
    

    Execute below command to verify docker has been installed -

    snap services docker
    
    # Command Output
    Service         Startup  Current
    docker.dockerd  enabled  active

    It also prints service name as 'docker.dockerd' that is different from service name when you deploy without using Snap package.

    Making Docker available without Root (Sudo) access


    You can execute below commands to create a user group called docker and adding your user to this group - 

    sudo groupadd docker
    # Add current user to docker group
    sudo usermod -aG docker $USER
    

    Please ensure to logout and login again (reboot in case you are installing it on a VM) to make these changes effective.

    You can verify this by executing following command with current user - 

    # Pulls and run hello-world image that simply prints docker hello-world message
    docker run hello-world

    Here is the sample output of above command - 

    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    d1725b59e92d: Pull complete
    Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     https://hub.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/get-started/

     

    Starting Docker using Snap


    You can start docker installed using Snap package using below command. Please note that it is run automatically after installation.

    sudo snap start docker

     

    Stopping Docker using Snap


    You can stóp docker installed using Snap package using below command-

    sudo snap stop docker

     

    Uninstalling Docker using Snap


    In order to uninstall or remove docker installed using Snap package, simply execute following command - 

    sudo snap remove docker

     

     

    Thank you for reading through the tutorial. In case of any feedback/questions/concerns, you can communicate same to us through your comments and we shall get back to you as soon as possible.

    Posted By: Amit Kumar
    Published on: 2018-10-19 02:10:08

    Comment Form is loading comments...